summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-10 17:49:50 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-10 20:52:11 +0100
commit646b37d1a9b1a7974d8815ed3ea888946e3a45d4 (patch)
treebfeec26a38b1e8622c657ecbd3680ca13c8b53c7 /Userland/Libraries/LibWeb/DOM
parent8d104b7de2634f84c33e890f6be2ab24c0a4065c (diff)
downloadserenity-646b37d1a9b1a7974d8815ed3ea888946e3a45d4.zip
LibWeb: Cache CSS rules in buckets to reduce number of rules checked
This patch introduces the StyleComputer::RuleCache, which divides all of our (author) CSS rules into buckets. Currently, there are two buckets: - Rules where a specific class must be present. - All other rules. This allows us to check a significantly smaller set of rules for each element, since we can skip over any rule that requires a class attribute not present on the element. This takes the typical numer of rules tested per element on Discord from ~16000 to ~550. :^) We can definitely improve the cache invalidation. It currently happens too often due to media queries. And we also need to make sure we invalidate when mutating style through CSSOM APIs.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index e9423c0bac..a0ef87151f 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1147,6 +1147,10 @@ void Document::evaluate_media_queries_and_report_changes()
for (auto& style_sheet : style_sheets().sheets()) {
style_sheet.evaluate_media_queries(window());
}
+
+ // FIXME: This invalidates too often!
+ // We should only invalidate when one or more @media rules changes evaluation status.
+ style_computer().invalidate_rule_cache();
}
NonnullRefPtr<DOMImplementation> Document::implementation() const