Title: [149557] trunk/Source/WebCore
Revision
149557
Author
[email protected]
Date
2013-05-04 08:03:26 -0700 (Sat, 04 May 2013)

Log Message

Remove CSS selector profiler branches from ElementRuleCollector loop.
<http://webkit.org/b/115581>

Reviewed by Antti Koivisto.

Templatize the method so we don't have to check for active inspector frontends on every
pass through the loop.

Time spent in this loop goes down from 0.5% to 0.2% on iTunes Store, WebCore binary size
goes up 480 bytes (sorry Benjamin, I'll make it up to you.)

* css/ElementRuleCollector.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::collectMatchingRulesForList):
(WebCore::ElementRuleCollector::doCollectMatchingRulesForList):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149556 => 149557)


--- trunk/Source/WebCore/ChangeLog	2013-05-04 14:00:57 UTC (rev 149556)
+++ trunk/Source/WebCore/ChangeLog	2013-05-04 15:03:26 UTC (rev 149557)
@@ -1,3 +1,21 @@
+2013-05-03  Andreas Kling  <[email protected]>
+
+        Remove CSS selector profiler branches from ElementRuleCollector loop.
+        <http://webkit.org/b/115581>
+
+        Reviewed by Antti Koivisto.
+
+        Templatize the method so we don't have to check for active inspector frontends on every
+        pass through the loop.
+
+        Time spent in this loop goes down from 0.5% to 0.2% on iTunes Store, WebCore binary size
+        goes up 480 bytes (sorry Benjamin, I'll make it up to you.)
+
+        * css/ElementRuleCollector.h:
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::collectMatchingRulesForList):
+        (WebCore::ElementRuleCollector::doCollectMatchingRulesForList):
+
 2013-04-30  Robert Hogan  <[email protected]>
 
         REGRESSION(r140907): Incorrect baseline on cells after updating vertical-align

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (149556 => 149557)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2013-05-04 14:00:57 UTC (rev 149556)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2013-05-04 15:03:26 UTC (rev 149557)
@@ -403,6 +403,16 @@
 
 void ElementRuleCollector::collectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
 {
+    if (UNLIKELY(InspectorInstrumentation::hasFrontends())) {
+        doCollectMatchingRulesForList<true>(rules, matchRequest, ruleRange);
+        return;
+    }
+    doCollectMatchingRulesForList<false>(rules, matchRequest, ruleRange);
+}
+
+template<bool hasInspectorFrontends>
+void ElementRuleCollector::doCollectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
+{
     if (!rules)
         return;
 
@@ -415,25 +425,30 @@
             continue;
 
         StyleRule* rule = ruleData.rule();
-        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchRule(document(), rule, m_inspectorCSSOMWrappers, document()->styleSheetCollection());
+        InspectorInstrumentationCookie cookie;
+        if (hasInspectorFrontends)
+            cookie = InspectorInstrumentation::willMatchRule(document(), rule, m_inspectorCSSOMWrappers, document()->styleSheetCollection());
         PseudoId dynamicPseudo = NOPSEUDO;
         if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo)) {
             // If the rule has no properties to apply, then ignore it in the non-debug mode.
             const StylePropertySet* properties = rule->properties();
             if (!properties || (properties->isEmpty() && !matchRequest.includeEmptyRules)) {
-                InspectorInstrumentation::didMatchRule(cookie, false);
+                if (hasInspectorFrontends)
+                    InspectorInstrumentation::didMatchRule(cookie, false);
                 continue;
             }
             // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed.
             if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) {
-                InspectorInstrumentation::didMatchRule(cookie, false);
+                if (hasInspectorFrontends)
+                    InspectorInstrumentation::didMatchRule(cookie, false);
                 continue;
             }
             // If we're matching normal rules, set a pseudo bit if
             // we really just matched a pseudo-element.
             if (dynamicPseudo != NOPSEUDO && m_pseudoStyleRequest.pseudoId == NOPSEUDO) {
                 if (m_mode == SelectorChecker::CollectingRules) {
-                    InspectorInstrumentation::didMatchRule(cookie, false);
+                    if (hasInspectorFrontends)
+                        InspectorInstrumentation::didMatchRule(cookie, false);
                     continue;
                 }
                 if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID)
@@ -446,11 +461,13 @@
 
                 // Add this rule to our list of matched rules.
                 addMatchedRule(&ruleData);
-                InspectorInstrumentation::didMatchRule(cookie, true);
+                if (hasInspectorFrontends)
+                    InspectorInstrumentation::didMatchRule(cookie, true);
                 continue;
             }
         }
-        InspectorInstrumentation::didMatchRule(cookie, false);
+        if (hasInspectorFrontends)
+            InspectorInstrumentation::didMatchRule(cookie, false);
     }
 }
 

Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (149556 => 149557)


--- trunk/Source/WebCore/css/ElementRuleCollector.h	2013-05-04 14:00:57 UTC (rev 149556)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h	2013-05-04 15:03:26 UTC (rev 149557)
@@ -92,6 +92,9 @@
     void clearMatchedRules();
         
 private:
+    template<bool hasInspectorFrontends>
+    void doCollectMatchingRulesForList(const Vector<RuleData>*, const MatchRequest&, StyleResolver::RuleRange&);
+
     const StyleResolver::State& m_state;
     DocumentRuleSets& m_ruleSets;
     SelectorFilter& m_selectorFilter;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to