perf(synced-lyrics): virtual scrolling #3162

Merged
arjix merged 17 commits from chore/synced-lyrics-virtual-scroll into master 2025-07-01 07:21:09 +00:00
Owner

An attempt to improve the performance of the synced-lyrics renderer.

TODO:

  • use virtua for the virtual scrolling
  • move calculation of current|previous|upcoming to the parent component
  • fix auto-scroll when the current line is not rendered
  • lyrics picker
    • auto show/hide based on scroll-state and/or mouse movement

This should massively improve the performance of the lyrics renderer, and prevent the huge lags that take place after switching songs.

An attempt to improve the performance of the synced-lyrics renderer. TODO: - [x] use [`virtua`](https://www.npmjs.com/package/virtua) for the virtual scrolling - [x] move calculation of `current`|`previous`|`upcoming` to the parent component - [x] fix auto-scroll when the current line is not rendered - [x] lyrics picker - - [x] keep mounted - https://github.com/inokawa/virtua/pull/681 - - [x] auto show/hide based on scroll-state and/or mouse movement This should massively improve the performance of the lyrics renderer, and prevent the huge lags that take place after switching songs.
JellyBrick (Migrated from github.com) requested changes 2025-03-30 22:58:55 +00:00
JellyBrick (Migrated from github.com) commented 2025-03-30 22:53:40 +00:00
    "virtua": "0.40.3",

Please use -E option like pnpm i -E virtua

```suggestion "virtua": "0.40.3", ``` Please use **-E** option like `pnpm i -E virtua`
@ -9,3 +9,3 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
JellyBrick (Migrated from github.com) commented 2025-03-30 22:58:37 +00:00

If moduleResolution is set to bundler, certain dependencies cannot be imported. e.g. youtubei.js.

If `moduleResolution` is set to `bundler`, certain dependencies cannot be imported. e.g. `youtubei.js`.
@ -9,3 +9,3 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
Author
Owner

can you ellaborate on that? I see the issue
any other moduleResolution introduces issues

well, technically we are using a bundler, so this is more correct
but I'll have to try to resolve that issue as well

~~can you ellaborate on that?~~ I see the issue any other `moduleResolution` introduces issues well, technically we are using a bundler, so this is more correct but I'll have to try to resolve that issue as well
@ -9,3 +9,3 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
Author
Owner

looks like it wasn't a big deal

looks like it wasn't a big deal
Author
Owner

I am actually stuck about the lyrics picker no longer auto-hiding.
I opened a discussion on the virtua repository to discuss how this should be properly done.

Otherwise, I'll have to resort to weird trickery using absolute positioning, which would look ass.

I am actually stuck about the lyrics picker no longer auto-hiding. I opened a [discussion](https://github.com/inokawa/virtua/discussions/669) on the `virtua` repository to discuss how this should be properly done. Otherwise, I'll have to resort to weird trickery using absolute positioning, which would look ass.
Author
Owner

by having a discriminated union, I can have the lyrics picker be an item in the virtual scroller, so I can make it have position: sticky!

image

div:has(> .lyrics-picker) {
  position: sticky !important;
}

so the only thing holding me back, is that the lyrics picker gets unmounted when you scroll away (because this is a virtual list)
waiting on https://github.com/inokawa/virtua/pull/681

by having a discriminated union, I can have the lyrics picker be an item in the virtual scroller, so I can make it have `position: sticky`! ![image](https://github.com/user-attachments/assets/431397ff-578f-4b79-aba5-ca5268178dbc) ```css div:has(> .lyrics-picker) { position: sticky !important; } ``` so the only thing holding me back, is that the lyrics picker gets unmounted when you scroll away (because this is a virtual list) waiting on https://github.com/inokawa/virtua/pull/681
Author
Owner

Alright, I think by the end of today I'll mark this PR ready for review!

Alright, I think by the end of today I'll mark this PR ready for review!
Author
Owner

@JellyBrick could you put a warning in the release notes, that this will likely break any custom CSS applied to the synced-lyrics?

@JellyBrick could you put a warning in the release notes, that this will likely break any custom CSS applied to the synced-lyrics?
Author
Owner

Squashed the commits because they were too many.

Squashed the commits because they were too many.
Author
Owner

@JellyBrick I decided to include a better romanization method in this PR

No need to worry about tiny-pinyin anymore, I not only fixed the w e i r d s p a c i n g it has for English, but I massively improved the quality of the romanized lyrics by using tinyld

and then as fallback I use the old detection methods, and I noticed a huge improvement in japanese/chinese songs

the reason I included these changes in this PR, is because it would be "laggy" to do it w/o virtual scrolling
virtual scrolling allows us to lazily romanize the lyrics

--

before:
image

after:
image

--

before:
image

after:
image

@JellyBrick I decided to include a better romanization method in this PR No need to worry about tiny-pinyin anymore, I not only fixed the `w e i r d s p a c i n g` it has for English, but I massively improved the quality of the romanized lyrics by using `tinyld` and then as fallback I use the old detection methods, and I noticed a huge improvement in japanese/chinese songs the reason I included these changes in this PR, is because it would be "laggy" to do it w/o virtual scrolling virtual scrolling allows us to lazily romanize the lyrics -- before: ![image](https://github.com/user-attachments/assets/8809af70-b505-4008-a081-50d4de8208a3) after: ![image](https://github.com/user-attachments/assets/cdba9a5a-ea84-4ef5-ae66-d815cfe43d24) -- before: ![image](https://github.com/user-attachments/assets/a749e383-ac91-4ff1-843d-12c394a13e48) after: ![image](https://github.com/user-attachments/assets/26651d57-d509-4bc7-a77f-08def9b79bd1)
JellyBrick (Migrated from github.com) requested changes 2025-06-30 03:44:33 +00:00
JellyBrick (Migrated from github.com) commented 2025-06-30 03:44:30 +00:00
    "tinyld": "1.3.4",
```suggestion "tinyld": "1.3.4", ```
JellyBrick (Migrated from github.com) approved these changes 2025-07-01 07:21:03 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: YTMD/youtube-music#3162
No description provided.