Title: [175427] trunk/Source/WebCore
Revision
175427
Author
[email protected]
Date
2014-10-31 14:43:30 -0700 (Fri, 31 Oct 2014)

Log Message

Make CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement() faster
https://bugs.webkit.org/show_bug.cgi?id=138227

Reviewed by Benjamin Poulain.

Restructure CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement()
a bit to do less if checks. The previous implementation was doing 7 if
checks no matter the input value. The new implementation does less
if checks depending on the input type.

Also, the isImageControlsRootElement() was showing in the profiles so
I updated the condition to only do this virtual function call if the
input is an HTMLDivElement (which we can check more efficiently).

With the change, I see that we're spending about ~26% less time in
this method when running speedometer. However, the impact on the
overall score is within noise.

No new tests, no behavior change.

* css/CSSDefaultStyleSheets.cpp:
(WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175426 => 175427)


--- trunk/Source/WebCore/ChangeLog	2014-10-31 21:27:10 UTC (rev 175426)
+++ trunk/Source/WebCore/ChangeLog	2014-10-31 21:43:30 UTC (rev 175427)
@@ -1,3 +1,28 @@
+2014-10-31  Chris Dumez  <[email protected]>
+
+        Make CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement() faster
+        https://bugs.webkit.org/show_bug.cgi?id=138227
+
+        Reviewed by Benjamin Poulain.
+
+        Restructure CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement()
+        a bit to do less if checks. The previous implementation was doing 7 if
+        checks no matter the input value. The new implementation does less
+        if checks depending on the input type.
+
+        Also, the isImageControlsRootElement() was showing in the profiles so
+        I updated the condition to only do this virtual function call if the
+        input is an HTMLDivElement (which we can check more efficiently).
+
+        With the change, I see that we're spending about ~26% less time in
+        this method when running speedometer. However, the impact on the
+        overall score is within noise.
+
+        No new tests, no behavior change.
+
+        * css/CSSDefaultStyleSheets.cpp:
+        (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):
+
 2014-10-31  Antti Koivisto  <[email protected]>
 
         Fix assertion in CachedResource::addDataBuffer

Modified: trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp (175426 => 175427)


--- trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp	2014-10-31 21:27:10 UTC (rev 175426)
+++ trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp	2014-10-31 21:43:30 UTC (rev 175427)
@@ -39,6 +39,7 @@
 #include "Page.h"
 #include "RenderTheme.h"
 #include "RuleSet.h"
+#include "SVGElement.h"
 #include "StyleSheetContents.h"
 #include "UserAgentStyleSheets.h"
 #include <wtf/NeverDestroyed.h>
@@ -158,36 +159,62 @@
         changedDefaultStyle = true;
     }
 
-    if (element.isSVGElement() && !svgStyleSheet) {
-        // SVG rules.
-        svgStyleSheet = parseUASheet(svgUserAgentStyleSheet, sizeof(svgUserAgentStyleSheet));
-        defaultStyle->addRulesFromSheet(svgStyleSheet, screenEval());
-        defaultPrintStyle->addRulesFromSheet(svgStyleSheet, printEval());
-        changedDefaultStyle = true;
+    if (is<HTMLElement>(element)) {
+        if (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element)) {
+            if (!plugInsStyleSheet) {
+                String plugInsRules = RenderTheme::themeForPage(element.document().page())->extraPlugInsStyleSheet() + element.document().page()->chrome().client().plugInExtraStyleSheet();
+                if (plugInsRules.isEmpty())
+                    plugInsRules = String(plugInsUserAgentStyleSheet, sizeof(plugInsUserAgentStyleSheet));
+                plugInsStyleSheet = parseUASheet(plugInsRules);
+                defaultStyle->addRulesFromSheet(plugInsStyleSheet, screenEval());
+                changedDefaultStyle = true;
+            }
+        }
+#if ENABLE(VIDEO)
+        else if (is<HTMLMediaElement>(element)) {
+            if (!mediaControlsStyleSheet) {
+                String mediaRules = RenderTheme::themeForPage(element.document().page())->mediaControlsStyleSheet();
+                if (mediaRules.isEmpty())
+                    mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::themeForPage(element.document().page())->extraMediaControlsStyleSheet();
+                mediaControlsStyleSheet = parseUASheet(mediaRules);
+                defaultStyle->addRulesFromSheet(mediaControlsStyleSheet, screenEval());
+                defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet, printEval());
+                changedDefaultStyle = true;
+            }
+        }
+#endif // ENABLE(VIDEO)
+#if ENABLE(SERVICE_CONTROLS)
+        else if (is<HTMLDivElement>(element) && element.isImageControlsRootElement()) {
+            if (!imageControlsStyleSheet) {
+                String imageControlsRules = RenderTheme::themeForPage(element.document().page())->imageControlsStyleSheet();
+                imageControlsStyleSheet = parseUASheet(imageControlsRules);
+                defaultStyle->addRulesFromSheet(imageControlsStyleSheet, screenEval());
+                defaultPrintStyle->addRulesFromSheet(imageControlsStyleSheet, printEval());
+                changedDefaultStyle = true;
+            }
+        }
+#endif // ENABLE(SERVICE_CONTROLS)
+    } else if (is<SVGElement>(element)) {
+        if (!svgStyleSheet) {
+            // SVG rules.
+            svgStyleSheet = parseUASheet(svgUserAgentStyleSheet, sizeof(svgUserAgentStyleSheet));
+            defaultStyle->addRulesFromSheet(svgStyleSheet, screenEval());
+            defaultPrintStyle->addRulesFromSheet(svgStyleSheet, printEval());
+            changedDefaultStyle = true;
+        }
     }
-
 #if ENABLE(MATHML)
-    if (is<MathMLElement>(element) && !mathMLStyleSheet) {
-        // MathML rules.
-        mathMLStyleSheet = parseUASheet(mathmlUserAgentStyleSheet, sizeof(mathmlUserAgentStyleSheet));
-        defaultStyle->addRulesFromSheet(mathMLStyleSheet, screenEval());
-        defaultPrintStyle->addRulesFromSheet(mathMLStyleSheet, printEval());
-        changedDefaultStyle = true;
+    else if (is<MathMLElement>(element)) {
+        if (!mathMLStyleSheet) {
+            // MathML rules.
+            mathMLStyleSheet = parseUASheet(mathmlUserAgentStyleSheet, sizeof(mathmlUserAgentStyleSheet));
+            defaultStyle->addRulesFromSheet(mathMLStyleSheet, screenEval());
+            defaultPrintStyle->addRulesFromSheet(mathMLStyleSheet, printEval());
+            changedDefaultStyle = true;
+        }
     }
-#endif
+#endif // ENABLE(MATHML)
 
-#if ENABLE(VIDEO)
-    if (!mediaControlsStyleSheet && is<HTMLMediaElement>(element)) {
-        String mediaRules = RenderTheme::themeForPage(element.document().page())->mediaControlsStyleSheet();
-        if (mediaRules.isEmpty())
-            mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::themeForPage(element.document().page())->extraMediaControlsStyleSheet();
-        mediaControlsStyleSheet = parseUASheet(mediaRules);
-        defaultStyle->addRulesFromSheet(mediaControlsStyleSheet, screenEval());
-        defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet, printEval());
-        changedDefaultStyle = true;
-    }
-#endif
-
 #if ENABLE(FULLSCREEN_API)
     if (!fullscreenStyleSheet && element.document().webkitIsFullScreen()) {
         String fullscreenRules = String(fullscreenUserAgentStyleSheet, sizeof(fullscreenUserAgentStyleSheet)) + RenderTheme::defaultTheme()->extraFullScreenStyleSheet();
@@ -196,27 +223,8 @@
         defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet, screenEval());
         changedDefaultStyle = true;
     }
-#endif
+#endif // ENABLE(FULLSCREEN_API)
 
-#if ENABLE(SERVICE_CONTROLS)
-    if (!imageControlsStyleSheet && element.isImageControlsRootElement()) {
-        String imageControlsRules = RenderTheme::themeForPage(element.document().page())->imageControlsStyleSheet();
-        imageControlsStyleSheet = parseUASheet(imageControlsRules);
-        defaultStyle->addRulesFromSheet(imageControlsStyleSheet, screenEval());
-        defaultPrintStyle->addRulesFromSheet(imageControlsStyleSheet, printEval());
-        changedDefaultStyle = true;
-    }
-#endif
-
-    if (!plugInsStyleSheet && (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element))) {
-        String plugInsRules = RenderTheme::themeForPage(element.document().page())->extraPlugInsStyleSheet() + element.document().page()->chrome().client().plugInExtraStyleSheet();
-        if (plugInsRules.isEmpty())
-            plugInsRules = String(plugInsUserAgentStyleSheet, sizeof(plugInsUserAgentStyleSheet));
-        plugInsStyleSheet = parseUASheet(plugInsRules);
-        defaultStyle->addRulesFromSheet(plugInsStyleSheet, screenEval());
-        changedDefaultStyle = true;
-    }
-
     ASSERT(defaultStyle->features().idsInRules.isEmpty());
     ASSERT(mathMLStyleSheet || defaultStyle->features().siblingRules.isEmpty());
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to