LibWeb: Skip :has() invalidation in update_style when nothing is pending

Add a document-level boolean flag that tracks whether any :has()
invalidations have been scheduled. This avoids iterating over all
shadow roots just to check is_empty() on each style scope when no
:has() invalidations are pending, which is the common case during
scrolling on complex pages like Reddit.

Results in ~10% reduction of is_empty() calls in profiles when
scrolling on Reddit.
This commit is contained in:
Aliaksandr Kalenik
2026-02-10 21:50:24 +01:00
committed by Alexander Kalenik
parent 38e53b5600
commit eea9837438
Notes: github-actions[bot] 2026-02-10 23:30:01 +00:00
4 changed files with 17 additions and 5 deletions

View File

@@ -1690,10 +1690,13 @@ void Document::update_style()
// style change event. [CSS-Transitions-2]
m_transition_generation++;
style_scope().invalidate_style_of_elements_affected_by_has();
for_each_shadow_root([&](auto& shadow_root) {
shadow_root.style_scope().invalidate_style_of_elements_affected_by_has();
});
if (m_needs_invalidation_of_elements_affected_by_has) {
m_needs_invalidation_of_elements_affected_by_has = false;
style_scope().invalidate_style_of_elements_affected_by_has();
for_each_shadow_root([&](auto& shadow_root) {
shadow_root.style_scope().invalidate_style_of_elements_affected_by_has();
});
}
if (!m_style_invalidator->has_pending_invalidations() && !needs_full_style_update() && !needs_style_update() && !child_needs_style_update())
return;