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

Guide on reflow and performance optimizations #26330

Open
twig-atl opened this issue Apr 21, 2023 · 7 comments
Open

Guide on reflow and performance optimizations #26330

twig-atl opened this issue Apr 21, 2023 · 7 comments
Labels
area: DOM/CSSOM Content:WebAPI Web API docs document not written Missing document page help wanted If you know something about this topic, we would love your help!

Comments

@twig-atl
Copy link

twig-atl commented Apr 21, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

What specific section or headline is this issue about?

getBoundingClientRect() triggers a reflow and performance issues

What information was incorrect, unhelpful, or incomplete?

It was missing something that might be vital for people when debugging issues.

What did you expect to see?

At least a remark or footnote about reflow.

Update from #27189 (comment):

Not sure that it's such a good idea to add this note. Reflow is quite complex and while it's true that it can be a perf bottleneck, such a note may make devs "fear" the APIs where they see that note and prefer less suitable APIs just because they didn't see the note there. For instance, all these getters and methods will only trigger a reflow when the box-model has been dirtied. Calling twice getBoundingClientRect() in a row, or even inside a ResizeObserver callback will not trigger a reflow. Also, some getters will only trigger a partial recalc, like getComputedStyle(element).fontStyle which only needs to walk up the tree from element to get the computed value, where getComputedStyle(element).width would need to recalculate the whole tree because it could be affected by siblings. So maybe if it did link to a complete tutorial on what is layout/reflow and what triggers it, that could be valuable, but even then, some are so unrelated that adding such a note to stuff like CanvasRenderingContext2d#fillText() sounds very weird.

Do you have any supporting links, references, or citations?

https://toruskit.com/blog/how-to-get-element-bounds-without-reflow/

Do you have anything more you want to share?

No response

MDN metadata

Page report details
@twig-atl twig-atl added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Apr 21, 2023
@github-actions github-actions bot added the Content:WebAPI Web API docs label Apr 21, 2023
@advitiya7
Copy link
Contributor

hey i want to contribute to this @twig-atl can you assign this issue to me?
thanks

@twig-atl
Copy link
Author

twig-atl commented May 2, 2023

@advitiya7 I don't have access to do that

@wbamberg
Copy link
Collaborator

wbamberg commented May 8, 2023

@advitiya7 , I've assigned you :). Thanks!

@Josh-Cena Josh-Cena added help wanted If you know something about this topic, we would love your help! and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Jun 26, 2023
@Josh-Cena
Copy link
Member

From #27189 (comment)

Not sure that it's such a good idea to add this note. Reflow is quite complex and while it's true that it can be a perf bottleneck, such a note may make devs "fear" the APIs where they see that note and prefer less suitable APIs just because they didn't see the note there. For instance, all these getters and methods will only trigger a reflow when the box-model has been dirtied. Calling twice getBoundingClientRect() in a row, or even inside a ResizeObserver callback will not trigger a reflow. Also, some getters will only trigger a partial recalc, like getComputedStyle(element).fontStyle which only needs to walk up the tree from element to get the computed value, where getComputedStyle(element).width would need to recalculate the whole tree because it could be affected by siblings. So maybe if it did link to a complete tutorial on what is layout/reflow and what triggers it, that could be valuable, but even then, some are so unrelated that adding such a note to stuff like CanvasRenderingContext2d#fillText() sounds very weird.

@Josh-Cena Josh-Cena changed the title Please add a note about getBoundingClientRect() forcing a reflow and performance issues getBoundingClientRect() forces a reflow and may have performance issues Jun 27, 2024
@Josh-Cena Josh-Cena changed the title getBoundingClientRect() forces a reflow and may have performance issues Guide on reflow and performance optimizations Jun 27, 2024
@wbamberg
Copy link
Collaborator

Maybe we should just close this issue then?

@Josh-Cena
Copy link
Member

Isn't a guide for handling reflow in order, though?

I understand that the performance cliff is only triggered in certain cases, but we probably still need to remind readers that it's not zero/low-cost like it may seem as a getter.

@wbamberg
Copy link
Collaborator

Oh, I only read the content, didn't notice the title change. Yes, we should I suppose, but perhaps make the description match?

@Josh-Cena Josh-Cena added the document not written Missing document page label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DOM/CSSOM Content:WebAPI Web API docs document not written Missing document page help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

No branches or pull requests

4 participants