Bug 1456561 - Reduce the number of WakeSceneBuilder messages. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 24 Apr 2018 13:27:05 -0400
changeset 787272 fe68ce231d8391cc4991cdcd7b6553f69d041d03
parent 787142 26e53729a10976f52e75efa44e17b5e054969fec
push id107702
push userkgupta@mozilla.com
push dateTue, 24 Apr 2018 17:27:44 +0000
reviewersbotond
bugs1456561
milestone61.0a1
Bug 1456561 - Reduce the number of WakeSceneBuilder messages. r?botond Avoid sending a flood of WakeSceneBuilder messages when we get a series of updater-thread tasks to run in quick succession. MozReview-Commit-ID: 2irXrsahMPt
gfx/layers/apz/src/APZUpdater.cpp
--- a/gfx/layers/apz/src/APZUpdater.cpp
+++ b/gfx/layers/apz/src/APZUpdater.cpp
@@ -351,30 +351,45 @@ APZUpdater::RunOnUpdaterThread(LayersId 
   }
 
   if (UsingWebRenderUpdaterThread()) {
     // If the updater thread is a WebRender thread, and we're not on it
     // right now, save the task in the queue. We will run tasks from the queue
     // during the callback from the updater thread, which we trigger by the
     // call to WakeSceneBuilder.
 
+    bool sendWakeMessage = true;
     { // scope lock
       MutexAutoLock lock(mQueueLock);
+      for (const auto& i : mUpdaterQueue) {
+        if (i.mLayersId == aLayersId) {
+          // If there's already a task in the queue with this layers id, then
+          // we must have previously sent a WakeSceneBuilder message (when
+          // adding the first task with this layers id to the queue). Either
+          // that hasn't been fully processed yet, or the layers id is blocked
+          // waiting for an epoch - in either case there's no point in sending
+          // another WakeSceneBuilder message.
+          sendWakeMessage = false;
+          break;
+        }
+      }
       mUpdaterQueue.push_back(QueuedTask { aLayersId, task });
     }
-    RefPtr<wr::WebRenderAPI> api = mApz->GetWebRenderAPI();
-    if (api) {
-      api->WakeSceneBuilder();
-    } else {
-      // Not sure if this can happen, but it might be possible. If it does,
-      // the task is in the queue, but if we didn't get a WebRenderAPI it
-      // might never run, or it might run later if we manage to get a
-      // WebRenderAPI later. For now let's just emit a warning, this can
-      // probably be upgraded to an assert later.
-      NS_WARNING("Possibly dropping task posted to updater thread");
+    if (sendWakeMessage) {
+      RefPtr<wr::WebRenderAPI> api = mApz->GetWebRenderAPI();
+      if (api) {
+        api->WakeSceneBuilder();
+      } else {
+        // Not sure if this can happen, but it might be possible. If it does,
+        // the task is in the queue, but if we didn't get a WebRenderAPI it
+        // might never run, or it might run later if we manage to get a
+        // WebRenderAPI later. For now let's just emit a warning, this can
+        // probably be upgraded to an assert later.
+        NS_WARNING("Possibly dropping task posted to updater thread");
+      }
     }
     return;
   }
 
   if (MessageLoop* loop = CompositorThreadHolder::Loop()) {
     loop->PostTask(task.forget());
   } else {
     // Could happen during startup