-
Notifications
You must be signed in to change notification settings - Fork 12
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] Reduce calls to getBoundingClientRect() #5
Comments
A quick and obvious win is to at least group capturing of width and height. This causes two layout calculations. |
You could further reduce the number of |
Hi! I'd like to mention that it'd better to avoid gbcr at all as its data is affected by paddings, borders, scrollbars and CSS transformations, while width and height properties of a content rectangle represent content width and content height respectively. And while using it you need to check whether an element being observed is not an inline element. Probably, the best thing to do would be to use either computed styles of width and height or clientWidth and clientHeight properties of an element. But the first approach gives incorrect results for an element whose box model is the border-box. And with client width/height you would only need to subtract paddings. |
In some browsers,
getBoundingClientRect()
forces a new layout calculation on each call.Currently, the resize-observer module calls
getBoundingClientRect()
multiple times during each animation frame, especially when the size has changed. We should instead cache this value the first time that it is called per animation frame and reuse that value.The text was updated successfully, but these errors were encountered: