Cache isSelfPaintingLayer() for better performance
authorjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jun 2012 04:20:47 +0000 (04:20 +0000)
committerjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jun 2012 04:20:47 +0000 (04:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=88464

Reviewed by Simon Fraser.

Covered by existing tests (repaint tests among them).

isSelfPaintingLayer() has shown up several times on some scrolling benchmarks due
to the function being called several time per paint phase. This change caches the
boolean at style change time.

On http://dglazkov.github.com/performance-tests/biggrid.html, this nearly speed-up
painting by 2 (lowering the time taken to paint the newly exposed area when scrolling
on a 10,000 * 100 table from 95ms to 50ms).

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::RenderLayer):
Initialized m_isSelfPaintingLayer here.

(WebCore::RenderLayer::paintLayer):
Changed the order of the checks to get the more likely check first.

(WebCore::RenderLayer::shouldBeSelfPaintingLayer):
Renamed from isSelfPaintingLayer to make m_isNormalFlowOnly.

(WebCore::RenderLayer::styleChanged):
Added code to update our cached m_isSelfPaintingLayer.

* rendering/RenderLayer.h:
(WebCore::RenderLayer::isSelfPaintingLayer):
Changed to return m_isSelfPaintingLayer.

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLayer.h

index 17074b87a32507148dbe695b0d5a95043d9bbb80..cbac033f912d042abd17b7b935c4b50b2fc6b03e 100644 (file)
@@ -1,3 +1,37 @@
+2012-06-06  Julien Chaffraix  <jchaffraix@webkit.org>
+
+        Cache isSelfPaintingLayer() for better performance
+        https://bugs.webkit.org/show_bug.cgi?id=88464
+
+        Reviewed by Simon Fraser.
+
+        Covered by existing tests (repaint tests among them).
+
+        isSelfPaintingLayer() has shown up several times on some scrolling benchmarks due
+        to the function being called several time per paint phase. This change caches the
+        boolean at style change time.
+        
+        On http://dglazkov.github.com/performance-tests/biggrid.html, this nearly speed-up
+        painting by 2 (lowering the time taken to paint the newly exposed area when scrolling
+        on a 10,000 * 100 table from 95ms to 50ms).
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::RenderLayer):
+        Initialized m_isSelfPaintingLayer here.
+
+        (WebCore::RenderLayer::paintLayer):
+        Changed the order of the checks to get the more likely check first.
+
+        (WebCore::RenderLayer::shouldBeSelfPaintingLayer):
+        Renamed from isSelfPaintingLayer to make m_isNormalFlowOnly.
+
+        (WebCore::RenderLayer::styleChanged):
+        Added code to update our cached m_isSelfPaintingLayer.
+
+        * rendering/RenderLayer.h:
+        (WebCore::RenderLayer::isSelfPaintingLayer):
+        Changed to return m_isSelfPaintingLayer.
+
 2012-06-06  Yoshifumi Inoue  <yosin@chromium.org>
 
         REGRESSION(r109729) [Form] Rendering of select/optgroup/option combination is too slow.
index 9e785f771e4ffc85f4873323a7fe881b6cb83090..da9e23758e2eb520a57391e40aa9412bbacc0dab 100644 (file)
@@ -169,6 +169,8 @@ RenderLayer::RenderLayer(RenderBoxModelObject* renderer)
     , m_resizer(0)
 {
     m_isNormalFlowOnly = shouldBeNormalFlowOnly();
+    m_isSelfPaintingLayer = shouldBeSelfPaintingLayer();
+
     // Non-stacking contexts should have empty z-order lists. As this is already the case,
     // there is no need to dirty / recompute these lists.
     m_zOrderListsDirty = isStackingContext();
@@ -2879,6 +2881,10 @@ void RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* context,
     }
 #endif
 
+    // Non self-painting leaf layers don't need to be painted as their renderer() should properly paint itself.
+    if (!isSelfPaintingLayer() && !firstChild())
+        return;
+
     if (shouldSuppressPaintingLayer(this))
         return;
     
@@ -2886,10 +2892,6 @@ void RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* context,
     if (!renderer()->opacity())
         return;
 
-    // Non self-painting leaf layers don't need to be painted as their renderer() should properly paint itself.
-    if (!isSelfPaintingLayer() && !firstChild())
-        return;
-
     if (paintsWithTransparency(paintBehavior))
         paintFlags |= PaintLayerHaveTransparency;
 
@@ -4659,7 +4661,7 @@ bool RenderLayer::shouldBeNormalFlowOnly() const
             && !isTransparent();
 }
 
-bool RenderLayer::isSelfPaintingLayer() const
+bool RenderLayer::shouldBeSelfPaintingLayer() const
 {
     return !isNormalFlowOnly()
         || renderer()->hasReflection()
@@ -4742,6 +4744,8 @@ void RenderLayer::styleChanged(StyleDifference, const RenderStyle* oldStyle)
         dirtyStackingContextZOrderLists();
     }
 
+    m_isSelfPaintingLayer = shouldBeSelfPaintingLayer();
+
     if (renderer()->style()->overflowX() == OMARQUEE && renderer()->style()->marqueeBehavior() != MNONE && renderer()->isBox()) {
         if (!m_marquee)
             m_marquee = new RenderMarquee(this);
index 4b07c6c2c28602426bc0c370a82db47f522715d3..d33e657890213bec20cb70e5494bdafb549967d7 100644 (file)
@@ -275,7 +275,7 @@ public:
     RenderMarquee* marquee() const { return m_marquee; }
 
     bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
-    bool isSelfPaintingLayer() const;
+    bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
 
     bool cannotBlitToWindow() const;
 
@@ -729,7 +729,9 @@ private:
     bool hasHorizontalOverflow() const;
     bool hasVerticalOverflow() const;
 
-    bool shouldBeNormalFlowOnly() const; 
+    bool shouldBeNormalFlowOnly() const;
+
+    bool shouldBeSelfPaintingLayer() const;
 
     int scrollPosition(Scrollbar*) const;
     
@@ -866,6 +868,8 @@ protected:
     bool m_normalFlowListDirty: 1;
     bool m_isNormalFlowOnly : 1;
 
+    bool m_isSelfPaintingLayer : 1;
+
     bool m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
                                  // we ended up painting this layer or any descendants (and therefore need to
                                  // blend).