LibWeb: Rebuild counter style cache lazily

Stop rebuilding the counter style cache from every style update.
That made unrelated restyles pay the full counter-style cost even when
no relevant stylesheet state had changed.

Dirty the cache when stylesheet rule caches are invalidated and rebuild
it on the first counter-style lookup instead. Also make cold cache
rebuilds include user stylesheets.

Add regression tests covering insertRule() and replaceSync() updates
that should make newly defined counter styles take effect.
This commit is contained in:
Andreas Kling
2026-04-05 11:20:32 +02:00
committed by Andreas Kling
parent 0b5ef8fa22
commit e2e3c7fcdf
Notes: github-actions[bot] 2026-04-05 10:35:26 +00:00
8 changed files with 108 additions and 9 deletions

View File

@@ -1800,9 +1800,6 @@ void Document::update_style()
build_registered_properties_cache();
// FIXME: We don't need to rebuild this cache on every style update, just if a @counter-style rule has changed.
build_counter_style_cache();
auto invalidation = update_style_recursively(*this, style_computer(), false, false, false);
if (!invalidation.is_none())
invalidate_display_list();
@@ -6659,6 +6656,14 @@ void Document::for_each_active_css_style_sheet(Function<void(CSS::CSSStyleSheet&
}
}
HashMap<FlyString, NonnullRefPtr<CSS::CounterStyle const>> const& Document::registered_counter_styles() const
{
if (m_needs_counter_style_cache_update)
const_cast<Document&>(*this).build_counter_style_cache();
return m_registered_counter_styles;
}
double Document::ensure_element_shared_css_random_base_value(CSS::RandomCachingKey const& random_caching_key)
{
return m_element_shared_css_random_base_value_cache.ensure(random_caching_key, []() {
@@ -8296,6 +8301,8 @@ void Document::build_counter_style_cache()
--i;
}
}
m_needs_counter_style_cache_update = false;
}
StringView to_string(SetNeedsLayoutReason reason)