Title: [253717] trunk/Source/WebCore
Revision
253717
Author
[email protected]
Date
2019-12-18 14:03:54 -0800 (Wed, 18 Dec 2019)

Log Message

Optimize Style::Invalidator for multiple RuleSet case
https://bugs.webkit.org/show_bug.cgi?id=205406

Reviewed by Zalan Bujtas.

* style/StyleInvalidator.cpp:
(WebCore::Style::m_dirtiesAllStyle):
(WebCore::Style::Invalidator::Invalidator):
(WebCore::Style::Invalidator::collectRuleInformation):

Collect bunch of bits so we don't need to traverse again.

(WebCore::Style::Invalidator::invalidateIfNeeded):

Bail out when we find a reson to invalidate.

(WebCore::Style::Invalidator::invalidateStyle):
(WebCore::Style::Invalidator::invalidateInShadowTreeIfNeeded):
* style/StyleInvalidator.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (253716 => 253717)


--- trunk/Source/WebCore/ChangeLog	2019-12-18 21:47:05 UTC (rev 253716)
+++ trunk/Source/WebCore/ChangeLog	2019-12-18 22:03:54 UTC (rev 253717)
@@ -1,3 +1,25 @@
+2019-12-18  Antti Koivisto  <[email protected]>
+
+        Optimize Style::Invalidator for multiple RuleSet case
+        https://bugs.webkit.org/show_bug.cgi?id=205406
+
+        Reviewed by Zalan Bujtas.
+
+        * style/StyleInvalidator.cpp:
+        (WebCore::Style::m_dirtiesAllStyle):
+        (WebCore::Style::Invalidator::Invalidator):
+        (WebCore::Style::Invalidator::collectRuleInformation):
+
+        Collect bunch of bits so we don't need to traverse again.
+
+        (WebCore::Style::Invalidator::invalidateIfNeeded):
+
+        Bail out when we find a reson to invalidate.
+
+        (WebCore::Style::Invalidator::invalidateStyle):
+        (WebCore::Style::Invalidator::invalidateInShadowTreeIfNeeded):
+        * style/StyleInvalidator.h:
+
 2019-12-18  Andres Gonzalez  <[email protected]>
 
         AXIsolatedObject support for spin button increment/decrementButton.

Modified: trunk/Source/WebCore/style/StyleInvalidator.cpp (253716 => 253717)


--- trunk/Source/WebCore/style/StyleInvalidator.cpp	2019-12-18 21:47:05 UTC (rev 253716)
+++ trunk/Source/WebCore/style/StyleInvalidator.cpp	2019-12-18 22:03:54 UTC (rev 253717)
@@ -93,26 +93,38 @@
     m_ownedRuleSet->disableAutoShrinkToFit();
     for (auto& sheet : sheets)
         m_ownedRuleSet->addRulesFromSheet(*sheet, mediaQueryEvaluator);
+
+    m_ruleInformation = collectRuleInformation();
 }
 
 Invalidator::Invalidator(const Vector<const RuleSet*, 1>& ruleSets)
     : m_ruleSets(ruleSets)
+    , m_ruleInformation(collectRuleInformation())
 {
     ASSERT(m_ruleSets.size());
 }
 
+Invalidator::RuleInformation Invalidator::collectRuleInformation()
+{
+    RuleInformation information;
+    for (auto* ruleSet : m_ruleSets) {
+        if (!ruleSet->slottedPseudoElementRules().isEmpty())
+            information.hasSlottedPseudoElementRules = true;
+        if (!ruleSet->hostPseudoClassRules().isEmpty())
+            information.hasHostPseudoClassRules = true;
+        if (ruleSet->hasShadowPseudoElementRules())
+            information.hasShadowPseudoElementRules = true;
+        if (!ruleSet->partPseudoElementRules().isEmpty())
+            information.hasPartPseudoElementRules = true;
+    }
+    return information;
+}
+
 Invalidator::CheckDescendants Invalidator::invalidateIfNeeded(Element& element, const SelectorFilter* filter)
 {
     invalidateInShadowTreeIfNeeded(element);
 
-    bool shouldCheckForSlots = [&] {
-        for (auto* ruleSet : m_ruleSets) {
-            if (!ruleSet->slottedPseudoElementRules().isEmpty() && !m_didInvalidateHostChildren)
-                return true;
-        }
-        return false;
-    }();
-
+    bool shouldCheckForSlots = m_ruleInformation.hasSlottedPseudoElementRules && !m_didInvalidateHostChildren;
     if (shouldCheckForSlots && is<HTMLSlotElement>(element)) {
         auto* containingShadowRoot = element.containingShadowRoot();
         if (containingShadowRoot && containingShadowRoot->host()) {
@@ -129,8 +141,10 @@
             ElementRuleCollector ruleCollector(element, *ruleSet, filter);
             ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
 
-            if (ruleCollector.matchesAnyAuthorRules())
+            if (ruleCollector.matchesAnyAuthorRules()) {
                 element.invalidateStyleInternal();
+                break;
+            }
         }
 
         return CheckDescendants::Yes;
@@ -200,10 +214,8 @@
 {
     ASSERT(!m_dirtiesAllStyle);
 
-    for (auto* ruleSet : m_ruleSets) {
-        if (!ruleSet->hostPseudoClassRules().isEmpty() && shadowRoot.host())
-            shadowRoot.host()->invalidateStyleInternal();
-    }
+    if (m_ruleInformation.hasHostPseudoClassRules && shadowRoot.host())
+        shadowRoot.host()->invalidateStyleInternal();
 
     for (auto& child : childrenOfType<Element>(shadowRoot)) {
         SelectorFilter filter;
@@ -297,17 +309,13 @@
     if (!shadowRoot)
         return;
 
+    // FIXME: This could do actual rule matching too.
+    if (m_ruleInformation.hasShadowPseudoElementRules)
+        element.invalidateStyleForSubtreeInternal();
 
-    for (auto* ruleSet : m_ruleSets) {
-        if (ruleSet->hasShadowPseudoElementRules()) {
-            // FIXME: This could do actual rule matching too.
-            element.invalidateStyleForSubtreeInternal();
-        }
-
-        // FIXME: More fine-grained invalidation for ::part()
-        if (!ruleSet->partPseudoElementRules().isEmpty())
-            invalidateShadowParts(*shadowRoot);
-    }
+    // FIXME: More fine-grained invalidation for ::part()
+    if (m_ruleInformation.hasPartPseudoElementRules)
+        invalidateShadowParts(*shadowRoot);
 }
 
 void Invalidator::addToMatchElementRuleSets(Invalidator::MatchElementRuleSets& matchElementRuleSets, const InvalidationRuleSet& invalidationRuleSet)

Modified: trunk/Source/WebCore/style/StyleInvalidator.h (253716 => 253717)


--- trunk/Source/WebCore/style/StyleInvalidator.h	2019-12-18 21:47:05 UTC (rev 253716)
+++ trunk/Source/WebCore/style/StyleInvalidator.h	2019-12-18 22:03:54 UTC (rev 253717)
@@ -67,8 +67,19 @@
     void invalidateInShadowTreeIfNeeded(Element&);
     void invalidateStyleWithMatchElement(Element&, MatchElement);
 
+    struct RuleInformation {
+        bool hasSlottedPseudoElementRules { false };
+        bool hasHostPseudoClassRules { false };
+        bool hasShadowPseudoElementRules { false };
+        bool hasPartPseudoElementRules { false };
+    };
+    RuleInformation collectRuleInformation();
+
     std::unique_ptr<RuleSet> m_ownedRuleSet;
-    Vector<const RuleSet*, 1> m_ruleSets;
+    const Vector<const RuleSet*, 1> m_ruleSets;
+
+    RuleInformation m_ruleInformation;
+
     bool m_dirtiesAllStyle { false };
     bool m_didInvalidateHostChildren { false };
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to