This repository was archived by the owner on Jan 18, 2022. It is now read-only.
Fix performance issue in applyMoveTransition #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
getBoundingClientRect
causes a DOM reflow when the DOM has been written to between calls (see http://stackoverflow.com/a/37686736/945863). So to avoid this, first callgetBoundingClientRect
on each element in one loop with no intermediate writes to the DOM, then use those results while writing to the DOM in a second loop.Potential issue with this PR: I'm not sure whether
frags
is outwardly visible. I use the property_newPos
on eachfrag
, which, if it's used by external code, will be stomped.Before this change, on a list of 23 elements, I was seeing this performance in Chrome:
Notice that each call to
getBoundingClientRect
takes around 30ms. With these changes, it now looks like:And the whole call to
applyMoveTransition
is down to 40ms.