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

Performance Issues - Layout Thrashing #227

Open
perqa opened this issue Dec 16, 2021 · 0 comments
Open

Performance Issues - Layout Thrashing #227

perqa opened this issue Dec 16, 2021 · 0 comments

Comments

@perqa
Copy link

perqa commented Dec 16, 2021

The current implementation uses getBoundingClientRect() and element properties like .clientHeight, .clientWidth, etc extensively. All of these will trigger the browser to synchronously calculate the style and layout. See https://gist.github.com/paulirish/5d52fb081b3570c81e3a for a complete list. This will cause issues if using animations or running apps on slow devices. Since one very good use-case for spatial navigation is SmartTVs, this is a real issue. SmartTVs are generally much slower than your average PC browser, and SmartTV apps usually have lots of animations.

I added this library to a an existing open-source movie application project, and navigated around a little bit. 30 elements were focused during this short navigation session, but getBoundingClientRect() was called 15587 times. Many elements were called repeatedly with getBoundingClientRect().

Maybe it is possible to configure the library in a better way, which I'm not aware of? One improvement would be if it was possible to add a focusable attribute to those elements that should be focusable, and then limit the focus candidate search to those. An id attribute for each focusable element would enable memoization of the boundingClientRects to avoid repeated calls to getBoundingClientRect(). Memoization would work well for SmartTV apps, since they don't resize. For web pages, memoization would have to be reset in case of resizing. In any case memoization should be optional and resettable.

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

1 participant