LibWeb: Include immediate child (>) combinator in ancestor filter

Before this change, the ancestor filter would only reject rules that
required a certain set of descendant strings (class, ID or tag name)
to be present in the current element's ancestor chain.

An immediate child is also a descendant, so we can include this
relationship in the ancestor filter as well.

This substantially improves the efficiency of the ancestor filter on
websites using Tailwind CSS.

For example, https://tailwindcss.com/ itself goes from full style
updates taking ~1400ms to ~350ms. Still *way* too long, but a huge
improvement nonetheless.
This commit is contained in:
Andreas Kling 2024-09-09 11:18:32 +02:00 committed by Andreas Kling
parent b365a5c42f
commit 34fdd0d44f
Notes: github-actions[bot] 2024-09-09 10:47:49 +00:00

View file

@ -44,7 +44,7 @@ void Selector::collect_ancestor_hashes()
auto last_combinator = m_compound_selectors.last().combinator;
for (ssize_t compound_selector_index = static_cast<ssize_t>(m_compound_selectors.size()) - 2; compound_selector_index >= 0; --compound_selector_index) {
auto const& compound_selector = m_compound_selectors[compound_selector_index];
if (last_combinator == Combinator::Descendant) {
if (last_combinator == Combinator::Descendant || last_combinator == Combinator::ImmediateChild) {
for (auto const& simple_selector : compound_selector.simple_selectors) {
switch (simple_selector.type) {
case SimpleSelector::Type::Id: