Avoid unnecessary copy-on-write in FillLayer style application.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Nov 2013 16:20:16 +0000 (16:20 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Nov 2013 16:20:16 +0000 (16:20 +0000)
<https://webkit.org/b/124878>

We ended up with a lot of cloned StyleBackgroundData objects on
HTML5-8266. This happened because we always forced a copy-on-write
when applying background-image:inherit / background-image:initial.

This patch adds early returns to both functions. In the "inherit"
case, we bail early if the target style already has the same fill
layer data as its parent style.

In the "initial" case, we optimize for the single-FillLayer case
and add an early return if the relevant value is either unset or
equal to the templatized initial value.

2.46 MB progression on HTML5-8266 locally.

Reviewed by Antti Koivisto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159782 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/DeprecatedStyleBuilder.cpp

index 89314d20554f3e520aa157e8270dc6dab87e6dc3..463b80e7733c3858e002c03537662a44988f6ac6 100644 (file)
@@ -1,3 +1,24 @@
+2013-11-26  Andreas Kling  <akling@apple.com>
+
+        Avoid unnecessary copy-on-write in FillLayer style application.
+        <https://webkit.org/b/124878>
+
+        We ended up with a lot of cloned StyleBackgroundData objects on
+        HTML5-8266. This happened because we always forced a copy-on-write
+        when applying background-image:inherit / background-image:initial.
+
+        This patch adds early returns to both functions. In the "inherit"
+        case, we bail early if the target style already has the same fill
+        layer data as its parent style.
+
+        In the "initial" case, we optimize for the single-FillLayer case
+        and add an early return if the relevant value is either unset or
+        equal to the templatized initial value.
+
+        2.46 MB progression on HTML5-8266 locally.
+
+        Reviewed by Antti Koivisto.
+
 2013-11-26  Antoine Quint  <graouts@apple.com>
 
         Web Inspector: Allow showing a context menu on all mouse events.
index 77fff079578027097c2480d0a72a070e0af11670..ff0a9316d96beaef826846a67f485fbb38aa5f60 100644 (file)
@@ -515,6 +515,10 @@ class ApplyPropertyFillLayer {
 public:
     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
     {
+        // Check for no-op before copying anything.
+        if (*(styleResolver->parentStyle()->*layersFunction)() == *(styleResolver->style()->*layersFunction)())
+            return;
+
         FillLayer* currChild = (styleResolver->style()->*accessLayersFunction)();
         FillLayer* prevChild = 0;
         const FillLayer* currParent = (styleResolver->parentStyle()->*layersFunction)();
@@ -539,6 +543,12 @@ public:
 
     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
     {
+        // Check for (single-layer) no-op before clearing anything.
+        const FillLayer& layers = *(styleResolver->style()->*layersFunction)();
+        bool firstLayerHasValue = (layers.*testFunction)();
+        if (!layers.next() && (!firstLayerHasValue || (layers.*getFunction)() == (*initialFunction)(fillLayerType)))
+            return;
+
         FillLayer* currChild = (styleResolver->style()->*accessLayersFunction)();
         (currChild->*setFunction)((*initialFunction)(fillLayerType));
         for (currChild = currChild->next(); currChild; currChild = currChild->next())