Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Focus file before modifying DOM to avoid forced reflows #58
Description of the Change
Focusing an element is considered a "read" operation. Since we were mutating the DOM before selecting the element, the focus call was causing a double forced reflow. By waiting until after the focus call to mutate the DOM, we avoid those forced reflows, which were taking ~220ms combined. While reflows still have to occur, they seem to be more efficient than the forced reflows as seen below. I've also set
Don't focus a file on creation. That however is not very user-friendly.
Removes a source of forced reflows and minorly improves the time it takes until the Archive View is usable.
If an exception occurs while creating the tree entries or updating the summary, the loading view will not be removed. Similarly with selecting the first file and actually adding the entries to the DOM.
I haven't tested this but it would seem okay to use this approach. A couple of questions/comments:
@as-cii yeah I agree that the forced reflows aren't really bad in this case because they happen anyways later on, but even before applying the updated containment rules the profiling was consistently showing 100-200ms improvements after fixing the reflows.
I'm highly skeptical that this could occur (as mostly all it does is append elements to the DOM), but I forgot to mention that even if it does happen a Notification will be generated. There was no special handling beforehand either, but now we hide the loading message after the tree entries have finished being generated rather than before (which also makes more sense logically).