LibWeb: Optimize inherited style update

This commit changes the strategy for updating inherited styles. Instead
of marking all potentially affected nodes during style invalidation, the
decision is now made on-the-fly during style recalculation. Child nodes
will only have their inherited styles recalculated if their parent's
properties have changed.

On Discord this allows to 1000x reduce number of nodes with recalculated
inherited style.
This commit is contained in:
Aliaksandr Kalenik 2025-02-11 15:31:23 +01:00 committed by Andreas Kling
commit 761e9aeaf7
Notes: github-actions[bot] 2025-02-11 18:24:07 +00:00
3 changed files with 13 additions and 44 deletions

View file

@ -533,11 +533,8 @@ void Node::invalidate_style(StyleInvalidationReason, Vector<CSS::InvalidationSet
} else if (options.invalidate_elements_that_use_css_custom_properties && element.style_uses_css_custom_properties()) {
needs_style_recalculation = true;
}
if (needs_style_recalculation) {
if (needs_style_recalculation)
element.set_needs_style_update(true);
} else {
element.set_needs_inherited_style_update(true);
}
return TraversalDecision::Continue;
});
};
@ -1394,22 +1391,6 @@ EventTarget* Node::get_parent(Event const&)
return parent();
}
void Node::set_needs_inherited_style_update(bool value)
{
if (m_needs_inherited_style_update == value)
return;
m_needs_inherited_style_update = value;
if (m_needs_inherited_style_update) {
for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = ancestor->parent_or_shadow_host()) {
if (ancestor->m_child_needs_style_update)
break;
ancestor->m_child_needs_style_update = true;
}
document().schedule_style_update();
}
}
void Node::set_needs_layout_tree_update(bool value)
{
if (m_needs_layout_tree_update == value)