From: akling@apple.com Date: Tue, 26 Nov 2013 16:20:16 +0000 (+0000) Subject: Avoid unnecessary copy-on-write in FillLayer style application. X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=3aa2873674e56bc6a44909aaaddd656b5b95309f Avoid unnecessary copy-on-write in FillLayer style application. 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 --- diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 89314d20554f..463b80e7733c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,24 @@ +2013-11-26 Andreas Kling + + Avoid unnecessary copy-on-write in FillLayer style application. + + + 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 Web Inspector: Allow showing a context menu on all mouse events. diff --git a/Source/WebCore/css/DeprecatedStyleBuilder.cpp b/Source/WebCore/css/DeprecatedStyleBuilder.cpp index 77fff0795780..ff0a9316d96b 100644 --- a/Source/WebCore/css/DeprecatedStyleBuilder.cpp +++ b/Source/WebCore/css/DeprecatedStyleBuilder.cpp @@ -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())