-
Notifications
You must be signed in to change notification settings - Fork 58
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
Window scroll listener causes scroll stuttering in Chrome #136
Comments
It is debounced, no? We only do work if the rAF handle isn’t set. If you have a test setup, maybe try making it passive? It shouldn’t help, but maybe it will. |
Is it debounced? Maybe I just updated issue description with content of issue that was reported in Gatsby so it's all in one place - I should have done this from the start. |
I mean, “not doing anything if the timer is already set” is pretty well debounced, no? |
It looks like the function calls from this package are taking <100 microseconds so not sure what could cause it. Every so often there's one or two 30+ms frames With listener (here there was a long period of dropped frames): Without listener: Chrome still drops frames without it but not as many it seems. It's also completely random. Maybe it's just Chrome's fault! |
Okay, thinking about this a little more – a lot of the work in the rAF handler (which is causing the stutter) on window scroll is to work around quirks in Firefox (when using hash navigation). Probably the best thing to do is to be conservative about when to save window scroll position. Ick. The best thing to do would be to only save window position before navigation in cases where we know that this is safe. This really depends on details of when e.g. popstate events fire, though. |
The scroll event is fired at about the same rate as the animation frames, so theoretically this will save the scroll position up 60 times per second (on a 60 Hz monitor) which seems a bit much, and sometimes causes constant style recalculations in scrollLeft.js. I noticed this while doing some performance critical animation work that was tied to the scroll position. Would it be possible to have timeout based debounced scroll event handler instead? I would rather have a 300+ ms (or something) delay on scroll position saving than degraded scroll performance. |
That sounds like a good idea to me. Ideally we should avoid checking/saving stuff while the user is actively scrolling as much as possible. |
Care to take a stab at a PR? |
Sure! It might take a few days before I have time to look at it though. |
The first thing was to realize that the page was not scrolling on click. I was able to test this with window.pageYOffset in the console to get the currents scroll position. As the #acctab-description tab was being hidden on click of #acctab-additional tab. this created the illusion of the page scrolling as the documents height was being reduced. // offset of elements above the tabs
|
|
It probably creates a minor performance issue on firefox android |
This is cross-posted issue from gatsbyjs/gatsby#12520
I don't have any context on internals of
scroll-behavior
package, but maybe adding some debounce to listener function could help?/cc @atomiks
The text was updated successfully, but these errors were encountered: