Servo/StyleUpdateOnDOMChange: Difference between revisions

Line 45: Line 45:
The RenderStyle has flags that indicate whether its kids are affected by various structural pseudo-classes and '+' or '~' combinators.  On DOM mutations, the first affected element after the change (in child list order) is marked as needing a style recalc, or the single first child of the parent if it might need a recalc.  If more things before the change might need a recalc, then the parent is marked as needing a style recalc, which will recalc all its kids.
The RenderStyle has flags that indicate whether its kids are affected by various structural pseudo-classes and '+' or '~' combinators.  On DOM mutations, the first affected element after the change (in child list order) is marked as needing a style recalc, or the single first child of the parent if it might need a recalc.  If more things before the change might need a recalc, then the parent is marked as needing a style recalc, which will recalc all its kids.


In all of these cases, when actually recomputing style on an element, a check is made to see whether its kids are affected by '+' or '~'.  If so, then if any child is flagged as needing style recalc either the child after it or all children after it (depending on whether '+' or '~' was involved) are also flagged as needing style recalc.
In all of these cases, when actually recomputing style on an element, a check is made to see whether its kids are affected by '+' or '~'.  If so, then if any child is flagged as needing style recalc either the child after it or all children after it (depending on whether '+' or '~' was involved) are also flagged as needing style recalc.  There are some bugs here around chains of multiple '+', I think.


The upshot is that in some cases WebKit ends up recomputing style on a lot more elements than Gecko does, as far as I can tell, but in others it ends up recomputing style on many fewer elements.  XXXbz At least the latter is the only way I can explain its behavior on the HTML5 spec.  What I don't undertstand is why it ends up with that behavior, since it flags the "children affected by" flags just as eagerly as Gecko does...  Anyone know offhand?
The upshot is that in some cases WebKit ends up recomputing style on a lot more elements than Gecko does, as far as I can tell, but in others it ends up recomputing style on many fewer elements.  For example, given a selector like ".foo ~ span" and a div that changes class from "foo" to "bar", Gecko will restyle all later siblings of the div, while WebKit will not do any work at all if there are no "span" kids, since it would never have marked the parent as being affected by the '+' in that case.  I'm not sure to what extent this affects insertion behavior, where it seems like the two should be more similar.  _Somehow_ WebKit seems to do better than Gecko on the HTML5 single-page spec scripts, and I can't figure out why at this point.  Perhaps this is simply because its style recomputation seems to be much cheaper than Gecko's to actually run.


The other upshot is that the work involved in individual attribute and state changes is much less than in Gecko, at the cost of more style recomputation.  The work involved in DOM insertion/deletion is about the same.
The other upshot is that the work involved in individual attribute and state changes is much less than in Gecko, at the cost of more style recomputation.  The work involved in DOM insertion/deletion is about the same.
308

edits