Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid flushSync on reverse lists / allow "starting at bottom" #628

Open
natew opened this issue Feb 15, 2025 · 4 comments
Open

Avoid flushSync on reverse lists / allow "starting at bottom" #628

natew opened this issue Feb 15, 2025 · 4 comments

Comments

@natew
Copy link

natew commented Feb 15, 2025

So first I just love virtua it works wonderfully well.

I've been profiling my app a bit and found that the flushSync calls during intiial render are really hurting performance though.

Some of it just seems to happen on it's own, but a good chunk comes from needing to scrollToIndex because its reversed.

I'd be happy to help contribute here, but would like to find a way to get rid of as many flushSync as possible.

@inokawa
Copy link
Owner

inokawa commented Feb 16, 2025

Hi, thank you for raising this issue.
I agree with that some of flushSync calls should be removed. It's also causing other issue (#470).

Currently flushSync has 2 purposes, to reduce blank screen on huge scroll

shouldSync = distance > viewportSize;

and to avoid layout shift on resize, especially when scrolling up.
shouldSync = true;

They might be overused. We can remove some of them if we doesn't see any visual difference after removing it (and E2Es should be passed). Maybe _scrollMode or other flags are usable to avoid calling flushSync in some specific situation.

@natew
Copy link
Author

natew commented Feb 18, 2025

I've been testing removing it, but unfortunately I can't get the reverse list to scroll to the bottom without it consistently, even if i add various delays and re-call scrollToIndex a few times, it seems to never be fully accurate. I'll have to check into a more precise change. We have content that sometimes is very tall or short which probably doesn't help.

@natew
Copy link
Author

natew commented Feb 18, 2025

Hm actually my problem goes deeper, it seems reverse mode doesn't load the last messages until after you call scrollToBottom, but then they load and change size and that means I need to retry scrolling to the bottom. Seems a better strategy would be to load the last messages up-front for reverse.

@inokawa
Copy link
Owner

inokawa commented Feb 19, 2025

Thanks for the report. I'll look into it myself when I have a time.

it seems reverse mode doesn't load the last messages until after you call scrollToBottom

It seems like a similar issue to #415 . Maybe we need a new prop for initial scroll on mount, or should defer initial render when scrollToIndex is called on mount (inside of useLayoutEffect? not sure it's possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants