Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Conversation

crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Sep 22, 2016

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 call getBoundingClientRect 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 each frag, 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:

screenshot from 2016-09-23 00-10-26

Notice that each call to getBoundingClientRect takes around 30ms. With these changes, it now looks like:

screenshot from 2016-09-23 00-16-39

And the whole call to applyMoveTransition is down to 40ms.

getBoundingClientRect causes a DOM reflow when the DOM has been written to
between calls (see http://stackoverflow.com/a/37686736/945863). So call gBCR
on each element first in one loop with no intermediate writes, then use those
results while writing to the DOM in a second loop.
@yyx990803 yyx990803 merged commit 5fa1141 into vuejs:master Sep 22, 2016
@yyx990803
Copy link
Member

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants