Bug 1560948 - Don't garbage collect workers in an ongoing memory pressure state because it likely won't help much r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 24 Jun 2019 18:21:53 +0100
changeset 479957 53c79fdf66930a1ab892051b0edcf404bc1670e6
parent 479956 4d57aaf5c4298fc9549df0b4f5ab375839daaf8b
child 479999 b592d9101222eb142e0d933e88e0f9a5bdfe1f87
push id113510
push userjcoppeard@mozilla.com
push dateTue, 25 Jun 2019 09:21:59 +0000
treeherdermozilla-inbound@53c79fdf6693 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1560948
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1560948 - Don't garbage collect workers in an ongoing memory pressure state because it likely won't help much r=smaug Ignore ongoing memory pressure events on workers like we do on the main thread. Differential Revision: https://phabricator.services.mozilla.com/D35678
dom/workers/RuntimeService.cpp
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -134,16 +134,17 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 
 #define PREF_WORKERS_MAX_HARDWARE_CONCURRENCY "dom.maxHardwareConcurrency"
 
 #define PREF_MAX_SCRIPT_RUN_TIME_CONTENT "dom.max_script_run_time"
 #define PREF_MAX_SCRIPT_RUN_TIME_CHROME "dom.max_chrome_script_run_time"
 
 #define GC_REQUEST_OBSERVER_TOPIC "child-gc-request"
 #define CC_REQUEST_OBSERVER_TOPIC "child-cc-request"
 #define MEMORY_PRESSURE_OBSERVER_TOPIC "memory-pressure"
+#define MEMORY_PRESSURE_ONGOING_DATA "low-memory-ongoing"
 
 #define BROADCAST_ALL_WORKERS(_func, ...)                         \
   PR_BEGIN_MACRO                                                  \
   AssertIsOnMainThread();                                         \
                                                                   \
   AutoTArray<WorkerPrivate*, 100> workers;                        \
   {                                                               \
     MutexAutoLock lock(mMutex);                                   \
@@ -2194,19 +2195,23 @@ RuntimeService::Observe(nsISupports* aSu
     GarbageCollectAllWorkers(/* shrinking = */ false);
     return NS_OK;
   }
   if (!strcmp(aTopic, CC_REQUEST_OBSERVER_TOPIC)) {
     CycleCollectAllWorkers();
     return NS_OK;
   }
   if (!strcmp(aTopic, MEMORY_PRESSURE_OBSERVER_TOPIC)) {
-    GarbageCollectAllWorkers(/* shrinking = */ true);
-    CycleCollectAllWorkers();
-    MemoryPressureAllWorkers();
+    // Don't continue to GC/CC if we are in an ongoing low-memory state since
+    // its very slow and it likely won't help us anyway.
+    if (!nsDependentString(aData).EqualsLiteral(MEMORY_PRESSURE_ONGOING_DATA)) {
+      GarbageCollectAllWorkers(/* shrinking = */ true);
+      CycleCollectAllWorkers();
+      MemoryPressureAllWorkers();
+    }
     return NS_OK;
   }
   if (!strcmp(aTopic, NS_IOSERVICE_OFFLINE_STATUS_TOPIC)) {
     SendOfflineStatusChangeEventToAllWorkers(NS_IsOffline());
     return NS_OK;
   }
 
   MOZ_ASSERT_UNREACHABLE("Unknown observer topic!");