Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getComputedStyle now skips restyling if possible

76 views
Skip to first unread message

Wei-Cheng Pan

unread,
Sep 28, 2017, 5:00:38 AM9/28/17
to dev-platform
Hi,

This week I landed bug 1363805[1], which will skip restyling if the
element does
not need that for getting correct value. Normal users should not notice any
difference, but this change may affect some test cases which need to force
restyle.

The optimization only happens when the element satisfies *all* the following
conditions:

1. The CSS property does not depend on layout.
2. getComputedStyle and the element belong to the same document.
3. The document does not need to restyle for this element, i.e.
3-1. The document has a presshell.
3-2. The style set has not changed yet.
3-3. All ancestors (including the element itself) are not animating.
3-4. All ancestors (including the element itself) do not need to restyle
     themselves.
4. All ancestor documents satisfy 3 for the sub-document.

For example, getComputedStyle(document.body).color will not trigger
restyling if
only descendants have changed but not document.body itself. If you are
not sure
(or just don't care about it), choose a layout dependent property will
do the
trick. (e.g.: getComputedStyle(document.body).width)

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1363805

Cheers,
Wei-Cheng Pan

Bobby Holley

unread,
Sep 28, 2017, 1:26:06 PM9/28/17
to Wei-Cheng Pan, dev-platform
This is a great optimization - thanks wcp!
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>

Emilio Cobos Álvarez

unread,
Sep 28, 2017, 6:33:22 PM9/28/17
to dev-pl...@lists.mozilla.org, wp...@mozilla.com
On 09/28/2017 11:00 AM, Wei-Cheng Pan wrote:
> Hi,
>
> This week I landed bug 1363805[1], which will skip restyling if the
> element does
> not need that for getting correct value. Normal users should not notice any
> difference, but this change may affect some test cases which need to force
> restyle.

Awesome! Thanks a lot for getting that landed, I know it was harder than
expected! :)

Just for the record, I happened to be looking at Blink code for
unrelated reasons, and found that we can probably optimize layout
flushes a bit better too.

I filed bug 1404140 with the details. I'll try to look at it, but I'm
probably not going to be able to fix it in the short-term. If you or
someone else can grab it sooner that would be absolutely lovely!

-- Emilio

0 new messages