Skip to content

Truly independent web browser

LibWeb: Evaluate each adopted sheet's media queries once per pass

Andreas Klingc064b939bd06
diff --git a/Libraries/LibWeb/CSS/Invalidation/MediaQueryInvalidator.cpp b/Libraries/LibWeb/CSS/Invalidation/MediaQueryInvalidator.cpp
index 2ae2857dff8..54ae9a6578d 100644
--- a/Libraries/LibWeb/CSS/Invalidation/MediaQueryInvalidator.cpp
+++ b/Libraries/LibWeb/CSS/Invalidation/MediaQueryInvalidator.cpp
@@ -27,7 +27,12 @@ void evaluate_media_rules_and_publish_conditions(DOM::Document& document)
HTML::note_rendering_trace_event("media rules evaluated"sv);
HashTable<StyleScope*> scopes_with_changed_layer_order;
+ // OPTIMIZATION: A sheet that many shadow roots adopt is evaluated once, not once per root. Its evaluation is the
+ // same for every scope that owns it, and the changes it finds go to all of them below.
+ HashTable<StyleSheetState*> evaluated_author_sheets;
Function<void(StyleSheetState&)> evaluate_author_sheet = [&](StyleSheetState& style_sheet) {
+ if (evaluated_author_sheets.set(&style_sheet) != HashSetResult::InsertedNewEntry)
+ return;
Parser::ValueParserFFI::NativeStyleSheetMediaEvaluation result {};
if (!style_sheet.evaluate_media_queries(document, result))
return;