LibWeb: Don't rebuild rule cache so eagerly to check for :has/:defined

Instead, change the APIs from "has :foo" to "may have :foo" and return
true if we don't have a valid rule cache at the moment.

This allows us to defer the rebuilding of the rule cache until a later
time, for the cost of a wider invalidation at the moment.

Do note that if our rule cache is invalid, the whole document has
invalid style anyway! So this is actually always less work. :^)

Knocks ~1 second of loading time off of https://wpt.fyi/
This commit is contained in:
Andreas Kling 2025-01-24 10:29:51 +01:00 committed by Andreas Kling
commit 4bef0d0aea
Notes: github-actions[bot] 2025-01-24 16:55:43 +00:00
5 changed files with 13 additions and 12 deletions

View file

@ -2530,7 +2530,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
void StyleComputer::build_rule_cache_if_needed() const
{
if (m_author_rule_cache && m_user_rule_cache && m_user_agent_rule_cache)
if (has_valid_rule_cache())
return;
const_cast<StyleComputer&>(*this).build_rule_cache();
}
@ -3077,19 +3077,19 @@ size_t StyleComputer::number_of_css_font_faces_with_loading_in_progress() const
return count;
}
bool StyleComputer::has_has_selectors() const
bool StyleComputer::may_have_has_selectors() const
{
if (!document().is_active())
return false;
if (!has_valid_rule_cache())
return true;
build_rule_cache_if_needed();
return m_selector_insights->has_has_selectors;
}
bool StyleComputer::has_defined_selectors() const
bool StyleComputer::may_have_defined_selectors() const
{
if (!document().is_active())
return false;
if (!has_valid_rule_cache())
return true;
build_rule_cache_if_needed();
return m_selector_insights->has_defined_selectors;