Should I cache calls to .getBoundingClientRect() (in mousemove for ex) or the browsers do that?

307 views
Skip to first unread message

Cyril Auburtin

unread,
Mar 26, 2016, 6:44:11 PM3/26/16
to blink-dev
knowing that getBoudingRect use things like quadtrees I'm not sure it's good to call it very frequently

I've seen chrome has a cache for .closest for example, does it cache also .getBoudingRect?

Cyril Auburtin

unread,
Mar 26, 2016, 6:53:12 PM3/26/16
to blink-dev

PhistucK

unread,
Mar 27, 2016, 1:35:12 AM3/27/16
to Cyril Auburtin, blink-dev
Looks like it triggers layout and then computes it. No cache.

closest is different since it does not care about layout, only the DOM hierarchy, which is a must simpler concept than layout. Also note that it looke like closest only caches the selector itself, the closest elements themselves are recomputed every time.


PhistucK

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.

cyril.a...@gmail.com

unread,
Mar 27, 2016, 12:01:05 PM3/27/16
to blink-dev, cyril.a...@gmail.com
ok thanks, is there an estimation of the cost of this function? does it depend on the element depth in the DOM?

PhistucK

unread,
Mar 27, 2016, 1:02:49 PM3/27/16
to Cyril Auburtin, blink-dev
Less on the element depth (but also) and more on the CSS rules.


PhistucK

cyril.a...@gmail.com

unread,
Mar 27, 2016, 1:07:36 PM3/27/16
to blink-dev, cyril.a...@gmail.com
ok thanks, reminds I just did a * {box-sizing: border-box;}, it seems working better with .getBoundingClientRect (for positioning overloays, or carets)
Reply all
Reply to author
Forward
0 new messages