LibWeb: Limit sibling style invalidation by max distance

If an element is affected only by selectors using the direct sibling
combinator `+`, we can calculate the maximum invalidation distance and
use it to limit style invalidation. For example, the selector
`.a + .b + .c` has a maximum invalidation distance of 2, meaning we can
skip invalidating any element affected by this selector if it's more
than two siblings away from the element that triggered the style
invalidation.

This change results in visible performance improvement when hovering
PR list on GitHub.
This commit is contained in:
Aliaksandr Kalenik 2025-03-10 16:16:08 +01:00 committed by Alexander Kalenik
commit 84ecaaa75c
Notes: github-actions[bot] 2025-03-10 17:57:49 +00:00
6 changed files with 61 additions and 10 deletions

View file

@ -271,12 +271,15 @@ public:
bool can_use_fast_matches() const { return m_can_use_fast_matches; }
bool can_use_ancestor_filter() const { return m_can_use_ancestor_filter; }
size_t sibling_invalidation_distance() const;
private:
explicit Selector(Vector<CompoundSelector>&&);
Vector<CompoundSelector> m_compound_selectors;
mutable Optional<u32> m_specificity;
Optional<Selector::PseudoElement> m_pseudo_element;
mutable Optional<size_t> m_sibling_invalidation_distance;
bool m_can_use_fast_matches { false };
bool m_can_use_ancestor_filter { false };
bool m_contains_the_nesting_selector { false };