Title: [275129] trunk/Source/WebCore
Revision
275129
Author
[email protected]
Date
2021-03-26 20:52:53 -0700 (Fri, 26 Mar 2021)

Log Message

Avoid heap allocation on the audio thread in BaseAudioContext::scheduleNodeDeletion()
https://bugs.webkit.org/show_bug.cgi?id=223825

Reviewed by Darin Adler.

Avoid heap allocation on the audio thread in BaseAudioContext::scheduleNodeDeletion()
for performance. Stop calling appendVector() on m_nodesToDelete since m_nodesToDelete
is always empty. We can use std::exchange() instead of appendVector() and clear() to
avoid the heap allocation.

The reason m_nodesToDelete is always empty is that BaseAudioContext::scheduleNodeDeletion()
relies on the m_isDeletionScheduled flag to avoid adding to m_nodesToDelete until
m_nodesToDelete is cleared on the main thread and the m_isDeletionScheduled gets reset.

* Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::clear):
(WebCore::BaseAudioContext::scheduleNodeDeletion):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275128 => 275129)


--- trunk/Source/WebCore/ChangeLog	2021-03-27 03:27:27 UTC (rev 275128)
+++ trunk/Source/WebCore/ChangeLog	2021-03-27 03:52:53 UTC (rev 275129)
@@ -1,3 +1,23 @@
+2021-03-26  Chris Dumez  <[email protected]>
+
+        Avoid heap allocation on the audio thread in BaseAudioContext::scheduleNodeDeletion()
+        https://bugs.webkit.org/show_bug.cgi?id=223825
+
+        Reviewed by Darin Adler.
+
+        Avoid heap allocation on the audio thread in BaseAudioContext::scheduleNodeDeletion()
+        for performance. Stop calling appendVector() on m_nodesToDelete since m_nodesToDelete
+        is always empty. We can use std::exchange() instead of appendVector() and clear() to
+        avoid the heap allocation.
+
+        The reason m_nodesToDelete is always empty is that BaseAudioContext::scheduleNodeDeletion()
+        relies on the m_isDeletionScheduled flag to avoid adding to m_nodesToDelete until
+        m_nodesToDelete is cleared on the main thread and the m_isDeletionScheduled gets reset.
+
+        * Modules/webaudio/BaseAudioContext.cpp:
+        (WebCore::BaseAudioContext::clear):
+        (WebCore::BaseAudioContext::scheduleNodeDeletion):
+
 2021-03-26  Patrick Angle  <[email protected]>
 
         Web Inspector: Grid layout labels can be drawn outside the viewport

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (275128 => 275129)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2021-03-27 03:27:27 UTC (rev 275128)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2021-03-27 03:52:53 UTC (rev 275129)
@@ -210,9 +210,8 @@
     // Audio thread is dead. Nobody will schedule node deletion action. Let's do it ourselves.
     do {
         deleteMarkedNodes();
-        m_nodesToDelete.appendVector(m_nodesMarkedForDeletion);
-        m_nodesMarkedForDeletion.clear();
-    } while (m_nodesToDelete.size());
+        m_nodesToDelete = std::exchange(m_nodesMarkedForDeletion, { });
+    } while (!m_nodesToDelete.isEmpty());
 
     clearPendingActivity();
 }
@@ -781,16 +780,15 @@
         return;
 
     // Make sure to call deleteMarkedNodes() on main thread.    
-    if (m_nodesMarkedForDeletion.size() && !m_isDeletionScheduled) {
+    if (!m_nodesMarkedForDeletion.isEmpty() && !m_isDeletionScheduled) {
+        ASSERT(m_nodesToDelete.isEmpty());
+        m_nodesToDelete = std::exchange(m_nodesMarkedForDeletion, { });
+
+        m_isDeletionScheduled = true;
+
         // Heap allocations are forbidden on the audio thread for performance reasons so we need to
         // explicitly allow the following allocation(s).
         DisableMallocRestrictionsForCurrentThreadScope disableMallocRestrictions;
-
-        m_nodesToDelete.appendVector(m_nodesMarkedForDeletion);
-        m_nodesMarkedForDeletion.clear();
-
-        m_isDeletionScheduled = true;
-
         callOnMainThread([protectedThis = makeRef(*this)]() mutable {
             protectedThis->deleteMarkedNodes();
         });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to