Title: [264008] trunk/Source
Revision
264008
Author
[email protected]
Date
2020-07-06 20:46:01 -0700 (Mon, 06 Jul 2020)

Log Message

High CPU usage on Stash search results pages
https://bugs.webkit.org/show_bug.cgi?id=214018
<rdar://problem/64832917>

Reviewed by Tim Horton.
Source/WebCore:

Stash search results pages can contain a lot of overflow:scroll areas, so scrolling thread CA commits
would take a long time because ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters() would
open and close a CA commit for each scroller.

Fix by not explicitly starting a CA commit, and only entering this code if a gesture is active and in
the momentum phase.

Also sprinkle BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS in more places that call into Core
Animation.

* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::repositionScrollingLayers):
(WebCore::ScrollingTreeFrameScrollingNodeMac::repositionRelatedLayers):
* page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm:
(WebCore::ScrollingTreeOverflowScrollingNodeMac::repositionScrollingLayers):
* page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
* page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
(WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):
(WebCore::ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters):

Source/WebKit:

Stash search results pages can contain a lot of overflow:scroll areas, so scrolling thread CA commits
would take a long time because ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters() would
open and close a CA commit for each scroller.

Fix by not explicitly starting a CA commit, and only entering this code if a gesture is active and in
the momentum phase.

Also sprinkle BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS in more places that call into Core
Animation.

* UIProcess/RemoteLayerTree/ios/ScrollingTreeFrameScrollingNodeRemoteIOS.mm:
(WebKit::ScrollingTreeFrameScrollingNodeRemoteIOS::repositionRelatedLayers):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264007 => 264008)


--- trunk/Source/WebCore/ChangeLog	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebCore/ChangeLog	2020-07-07 03:46:01 UTC (rev 264008)
@@ -1,5 +1,33 @@
 2020-07-06  Simon Fraser  <[email protected]>
 
+        High CPU usage on Stash search results pages
+        https://bugs.webkit.org/show_bug.cgi?id=214018
+        <rdar://problem/64832917>
+
+        Reviewed by Tim Horton.
+
+        Stash search results pages can contain a lot of overflow:scroll areas, so scrolling thread CA commits
+        would take a long time because ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters() would
+        open and close a CA commit for each scroller.
+
+        Fix by not explicitly starting a CA commit, and only entering this code if a gesture is active and in
+        the momentum phase.
+
+        Also sprinkle BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS in more places that call into Core
+        Animation.
+
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::repositionScrollingLayers):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::repositionRelatedLayers):
+        * page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeOverflowScrollingNodeMac::repositionScrollingLayers):
+        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
+        * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
+        (WebCore::ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent):
+        (WebCore::ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters):
+
+2020-07-06  Simon Fraser  <[email protected]>
+
         BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS should not have trailing semicolons
         https://bugs.webkit.org/show_bug.cgi?id=214019
 

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm (264007 => 264008)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm	2020-07-07 03:46:01 UTC (rev 264008)
@@ -38,6 +38,7 @@
 #import "ScrollingTree.h"
 #import "TileController.h"
 #import "WebCoreCALayerExtras.h"
+#import <wtf/BlockObjCExceptions.h>
 #import <wtf/Deque.h>
 #import <wtf/text/CString.h>
 #import <wtf/text/TextStream.h>
@@ -158,12 +159,15 @@
 
 void ScrollingTreeFrameScrollingNodeMac::repositionScrollingLayers()
 {
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
     // We use scroll position here because the root content layer is offset to account for scrollOrigin (see FrameView::positionForRootContentLayer).
     static_cast<CALayer*>(scrolledContentsLayer()).position = -currentScrollPosition();
+    END_BLOCK_OBJC_EXCEPTIONS
 }
 
 void ScrollingTreeFrameScrollingNodeMac::repositionRelatedLayers()
 {
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
     auto scrollPosition = currentScrollPosition();
     auto layoutViewport = this->layoutViewport();
 
@@ -191,6 +195,7 @@
         if (m_footerLayer)
             m_footerLayer.get().position = FloatPoint(horizontalScrollOffsetForBanner, FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, totalContentsSize().height(), footerHeight()));
     }
+    END_BLOCK_OBJC_EXCEPTIONS
 
     m_delegate.updateScrollbarPainters();
 }

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm (264007 => 264008)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeOverflowScrollingNodeMac.mm	2020-07-07 03:46:01 UTC (rev 264008)
@@ -32,6 +32,7 @@
 #import "ScrollingStateOverflowScrollingNode.h"
 #import "ScrollingTree.h"
 #import "WebCoreCALayerExtras.h"
+#import <wtf/BlockObjCExceptions.h>
 #import <wtf/text/TextStream.h>
 
 namespace WebCore {
@@ -93,7 +94,9 @@
 
 void ScrollingTreeOverflowScrollingNodeMac::repositionScrollingLayers()
 {
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
     [static_cast<CALayer*>(scrollContainerLayer()) _web_setLayerBoundsOrigin:currentScrollOffset()];
+    END_BLOCK_OBJC_EXCEPTIONS
 }
 
 void ScrollingTreeOverflowScrollingNodeMac::repositionRelatedLayers()

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h (264007 => 264008)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h	2020-07-07 03:46:01 UTC (rev 264008)
@@ -95,6 +95,8 @@
     void releaseReferencesToScrollerImpsOnTheMainThread();
 
     ScrollController m_scrollController;
+    
+    bool m_inMomentumPhase { false };
 
     RetainPtr<NSScrollerImp> m_verticalScrollerImp;
     RetainPtr<NSScrollerImp> m_horizontalScrollerImp;

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm (264007 => 264008)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm	2020-07-07 03:46:01 UTC (rev 264008)
@@ -35,6 +35,7 @@
 #import "ScrollingTreeScrollingNode.h"
 #import <QuartzCore/QuartzCore.h>
 #import <pal/spi/mac/NSScrollerImpSPI.h>
+#import <wtf/BlockObjCExceptions.h>
 
 namespace WebCore {
 
@@ -121,14 +122,17 @@
 
 bool ScrollingTreeScrollingNodeDelegateMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
 {
-    if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseBegan) {
-        [m_verticalScrollerImp setUsePresentationValue:YES];
-        [m_horizontalScrollerImp setUsePresentationValue:YES];
+    bool wasInMomentumPhase = m_inMomentumPhase;
+
+    if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseBegan)
+        m_inMomentumPhase = true;
+    else if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded || wheelEvent.momentumPhase() == PlatformWheelEventPhaseCancelled)
+        m_inMomentumPhase = false;
+    
+    if (wasInMomentumPhase != m_inMomentumPhase) {
+        [m_verticalScrollerImp setUsePresentationValue:m_inMomentumPhase];
+        [m_horizontalScrollerImp setUsePresentationValue:m_inMomentumPhase];
     }
-    if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded || wheelEvent.momentumPhase() == PlatformWheelEventPhaseCancelled) {
-        [m_verticalScrollerImp setUsePresentationValue:NO];
-        [m_horizontalScrollerImp setUsePresentationValue:NO];
-    }
 
 #if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)
     if (scrollingTree().isMonitoringWheelEvents())
@@ -388,10 +392,10 @@
 
 void ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters()
 {
-    if (m_verticalScrollerImp || m_horizontalScrollerImp) {
+    if (m_inMomentumPhase && (m_verticalScrollerImp || m_horizontalScrollerImp)) {
+        BEGIN_BLOCK_OBJC_EXCEPTIONS
         auto scrollOffset = scrollingNode().currentScrollOffset();
 
-        [CATransaction begin];
         [CATransaction lock];
 
         if ([m_verticalScrollerImp shouldUsePresentationValue]) {
@@ -409,7 +413,7 @@
         }
 
         [CATransaction unlock];
-        [CATransaction commit];
+        END_BLOCK_OBJC_EXCEPTIONS
     }
 }
 

Modified: trunk/Source/WebKit/ChangeLog (264007 => 264008)


--- trunk/Source/WebKit/ChangeLog	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebKit/ChangeLog	2020-07-07 03:46:01 UTC (rev 264008)
@@ -1,5 +1,26 @@
 2020-07-06  Simon Fraser  <[email protected]>
 
+        High CPU usage on Stash search results pages
+        https://bugs.webkit.org/show_bug.cgi?id=214018
+        <rdar://problem/64832917>
+
+        Reviewed by Tim Horton.
+        
+        Stash search results pages can contain a lot of overflow:scroll areas, so scrolling thread CA commits
+        would take a long time because ScrollingTreeScrollingNodeDelegateMac::updateScrollbarPainters() would
+        open and close a CA commit for each scroller.
+
+        Fix by not explicitly starting a CA commit, and only entering this code if a gesture is active and in
+        the momentum phase.
+
+        Also sprinkle BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS in more places that call into Core
+        Animation.
+
+        * UIProcess/RemoteLayerTree/ios/ScrollingTreeFrameScrollingNodeRemoteIOS.mm:
+        (WebKit::ScrollingTreeFrameScrollingNodeRemoteIOS::repositionRelatedLayers):
+
+2020-07-06  Simon Fraser  <[email protected]>
+
         BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS should not have trailing semicolons
         https://bugs.webkit.org/show_bug.cgi?id=214019
 

Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeFrameScrollingNodeRemoteIOS.mm (264007 => 264008)


--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeFrameScrollingNodeRemoteIOS.mm	2020-07-07 03:35:47 UTC (rev 264007)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeFrameScrollingNodeRemoteIOS.mm	2020-07-07 03:46:01 UTC (rev 264008)
@@ -32,6 +32,7 @@
 #import <WebCore/ScrollingStateFrameScrollingNode.h>
 #import <WebCore/ScrollingStateScrollingNode.h>
 #import <WebCore/ScrollingTree.h>
+#import <wtf/BlockObjCExceptions.h>
 
 namespace WebKit {
 using namespace WebCore;
@@ -127,6 +128,7 @@
 
 void ScrollingTreeFrameScrollingNodeRemoteIOS::repositionRelatedLayers()
 {
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
     auto layoutViewport = this->layoutViewport();
 
     [m_counterScrollingLayer setPosition:layoutViewport.location()];
@@ -142,6 +144,7 @@
         if (m_footerLayer)
             [m_footerLayer setPosition:FloatPoint(layoutViewport.x(), totalContentsSize().height() - footerHeight())];
     }
+    END_BLOCK_OBJC_EXCEPTIONS
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to