Title: [292330] branches/safari-613-branch/Source/WebCore/rendering
Revision
292330
Author
[email protected]
Date
2022-04-04 14:55:30 -0700 (Mon, 04 Apr 2022)

Log Message

Cherry-pick r289692. rdar://91259284

    Make WidgetHierarchyUpdatesSuspensionScope cheaper if it has nothing to do
    https://bugs.webkit.org/show_bug.cgi?id=236486

    Reviewed by Simon Fraser.

    With content that does a lot of DOM manipulation, we can create and
    destroy a WidgetHierarchyUpdatesSuspensionScope on the stack many times.
    When this object has nothing to do, it calls an out of line function.
    This patch pulls out the check for whether it needs to call
    moveWidgets() into the inline destructor.

    This is a 1% saving on the jQuery-TodoMVC subtest of Speedometer 2,
    though the effect on the top line score is minimal.

    rendering/RenderWidget.cpp:
    (WebCore::WidgetHierarchyUpdatesSuspensionScope::moveWidgets):

    rendering/RenderWidget.h:
    (WebCore::WidgetHierarchyUpdatesSuspensionScope::~WidgetHierarchyUpdatesSuspensionScope):
    (WebCore::WidgetHierarchyUpdatesSuspensionScope::scheduleWidgetToMove):

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.cpp (292329 => 292330)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.cpp	2022-04-04 21:55:27 UTC (rev 292329)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.cpp	2022-04-04 21:55:30 UTC (rev 292330)
@@ -49,6 +49,7 @@
 }
 
 unsigned WidgetHierarchyUpdatesSuspensionScope::s_widgetHierarchyUpdateSuspendCount = 0;
+bool WidgetHierarchyUpdatesSuspensionScope::s_haveScheduledWidgetToMove = false;
 
 WidgetHierarchyUpdatesSuspensionScope::WidgetToParentMap& WidgetHierarchyUpdatesSuspensionScope::widgetNewParentMap()
 {
@@ -58,6 +59,7 @@
 
 void WidgetHierarchyUpdatesSuspensionScope::moveWidgets()
 {
+    ASSERT(s_haveScheduledWidgetToMove);
     while (!widgetNewParentMap().isEmpty()) {
         auto map = std::exchange(widgetNewParentMap(), { });
         for (auto& entry : map) {
@@ -72,6 +74,7 @@
             }
         }
     }
+    s_haveScheduledWidgetToMove = false;
 }
 
 static void moveWidgetToParentSoon(Widget& child, FrameView* parent)

Modified: branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.h (292329 => 292330)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.h	2022-04-04 21:55:27 UTC (rev 292329)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderWidget.h	2022-04-04 21:55:30 UTC (rev 292330)
@@ -37,13 +37,13 @@
     ~WidgetHierarchyUpdatesSuspensionScope()
     {
         ASSERT(s_widgetHierarchyUpdateSuspendCount);
-        if (s_widgetHierarchyUpdateSuspendCount == 1)
+        if (s_widgetHierarchyUpdateSuspendCount == 1 && s_haveScheduledWidgetToMove)
             moveWidgets();
         s_widgetHierarchyUpdateSuspendCount--;
     }
 
     static bool isSuspended() { return s_widgetHierarchyUpdateSuspendCount; }
-    static void scheduleWidgetToMove(Widget& widget, FrameView* frame) { widgetNewParentMap().set(&widget, frame); }
+    static void scheduleWidgetToMove(Widget&, FrameView*);
 
 private:
     using WidgetToParentMap = HashMap<RefPtr<Widget>, FrameView*>;
@@ -51,8 +51,15 @@
 
     WEBCORE_EXPORT void moveWidgets();
     WEBCORE_EXPORT static unsigned s_widgetHierarchyUpdateSuspendCount;
+    WEBCORE_EXPORT static bool s_haveScheduledWidgetToMove;
 };
-    
+
+inline void WidgetHierarchyUpdatesSuspensionScope::scheduleWidgetToMove(Widget& widget, FrameView* frame)
+{
+    s_haveScheduledWidgetToMove = true;
+    widgetNewParentMap().set(&widget, frame);
+}
+
 class RenderWidget : public RenderReplaced, private OverlapTestRequestClient {
     WTF_MAKE_ISO_ALLOCATED(RenderWidget);
 public:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to