Bug 1725584 - Update JS_SetGCParametersBasedOnAvailableMemory with reasonable current values r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 13 Aug 2021 13:58:25 +0000
changeset 588834 528851a846b44801c398431c4415d3c9a8773ece
parent 588833 2125b851d061ce1a66ebaac9ac109240cbf661e8
child 588835 c925daa31146272ae0e6702b72597520eb34f129
push id38704
push usernerli@mozilla.com
push dateFri, 13 Aug 2021 21:52:47 +0000
treeherdermozilla-central@df4b218d495a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1725584
milestone93.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 1725584 - Update JS_SetGCParametersBasedOnAvailableMemory with reasonable current values r=sfink This function is only used by the shell, and then only when --avilable-memory is passed, but it could be used as a source of parameter values for low memory systems so we should make them resonable at least. Looking at this the current normal values are out of date with the defaults, and one parameter is repeated several times. I'm not sure what happened here. Depends on D122601 Differential Revision: https://phabricator.services.mozilla.com/D122602
js/public/GCAPI.h
js/src/jsapi.cpp
js/src/shell/js.cpp
--- a/js/public/GCAPI.h
+++ b/js/public/GCAPI.h
@@ -1149,17 +1149,17 @@ extern JS_PUBLIC_API void JS_SetGCParame
                                             uint32_t value);
 
 extern JS_PUBLIC_API void JS_ResetGCParameter(JSContext* cx, JSGCParamKey key);
 
 extern JS_PUBLIC_API uint32_t JS_GetGCParameter(JSContext* cx,
                                                 JSGCParamKey key);
 
 extern JS_PUBLIC_API void JS_SetGCParametersBasedOnAvailableMemory(
-    JSContext* cx, uint32_t availMem);
+    JSContext* cx, uint32_t availMemMB);
 
 /**
  * Create a new JSString whose chars member refers to external memory, i.e.,
  * memory requiring application-specific finalization.
  */
 extern JS_PUBLIC_API JSString* JS_NewExternalString(
     JSContext* cx, const char16_t* chars, size_t length,
     const JSExternalStringCallbacks* callbacks);
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1419,50 +1419,52 @@ JS_PUBLIC_API void JS_SetGCParameter(JSC
 JS_PUBLIC_API void JS_ResetGCParameter(JSContext* cx, JSGCParamKey key) {
   cx->runtime()->gc.resetParameter(key);
 }
 
 JS_PUBLIC_API uint32_t JS_GetGCParameter(JSContext* cx, JSGCParamKey key) {
   return cx->runtime()->gc.getParameter(key);
 }
 
-JS_PUBLIC_API void JS_SetGCParametersBasedOnAvailableMemory(JSContext* cx,
-                                                            uint32_t availMem) {
+JS_PUBLIC_API void JS_SetGCParametersBasedOnAvailableMemory(
+    JSContext* cx, uint32_t availMemMB) {
   struct JSGCConfig {
     JSGCParamKey key;
     uint32_t value;
   };
 
   static const JSGCConfig minimal[] = {
-      {JSGC_SLICE_TIME_BUDGET_MS, 30},
+      {JSGC_SLICE_TIME_BUDGET_MS, 5},
       {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_LARGE_HEAP_SIZE_MIN, 40},
-      {JSGC_SMALL_HEAP_SIZE_MAX, 0},
+      {JSGC_LARGE_HEAP_SIZE_MIN, 250},
+      {JSGC_SMALL_HEAP_SIZE_MAX, 50},
       {JSGC_HIGH_FREQUENCY_SMALL_HEAP_GROWTH, 300},
       {JSGC_HIGH_FREQUENCY_LARGE_HEAP_GROWTH, 120},
       {JSGC_LOW_FREQUENCY_HEAP_GROWTH, 120},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_ALLOCATION_THRESHOLD, 1}};
+      {JSGC_ALLOCATION_THRESHOLD, 15},
+      {JSGC_MALLOC_THRESHOLD_BASE, 20},
+      {JSGC_SMALL_HEAP_INCREMENTAL_LIMIT, 200},
+      {JSGC_LARGE_HEAP_INCREMENTAL_LIMIT, 110},
+      {JSGC_URGENT_THRESHOLD_MB, 8}};
 
   static const JSGCConfig nominal[] = {
-      {JSGC_SLICE_TIME_BUDGET_MS, 30},
+      {JSGC_SLICE_TIME_BUDGET_MS, 5},
       {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1000},
       {JSGC_LARGE_HEAP_SIZE_MIN, 500},
       {JSGC_SMALL_HEAP_SIZE_MAX, 100},
       {JSGC_HIGH_FREQUENCY_SMALL_HEAP_GROWTH, 300},
       {JSGC_HIGH_FREQUENCY_LARGE_HEAP_GROWTH, 150},
       {JSGC_LOW_FREQUENCY_HEAP_GROWTH, 150},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_HIGH_FREQUENCY_TIME_LIMIT, 1500},
-      {JSGC_ALLOCATION_THRESHOLD, 30}};
-
-  const auto& configSet = availMem > 512 ? nominal : minimal;
+      {JSGC_ALLOCATION_THRESHOLD, 27},
+      {JSGC_MALLOC_THRESHOLD_BASE, 38},
+      {JSGC_SMALL_HEAP_INCREMENTAL_LIMIT, 140},
+      {JSGC_LARGE_HEAP_INCREMENTAL_LIMIT, 110},
+      {JSGC_URGENT_THRESHOLD_MB, 16}};
+
+  const auto& configSet = availMemMB > 512 ? nominal : minimal;
   for (const auto& config : configSet) {
     JS_SetGCParameter(cx, config.key, config.value);
   }
 }
 
 JS_PUBLIC_API JSString* JS_NewExternalString(
     JSContext* cx, const char16_t* chars, size_t length,
     const JSExternalStringCallbacks* callbacks) {
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -12660,19 +12660,19 @@ int main(int argc, char** argv) {
   JS_SetFutexCanWait(cx);
   JS::SetWarningReporter(cx, WarningReporter);
   if (!SetContextOptions(cx, op)) {
     return 1;
   }
 
   JS_SetGCParameter(cx, JSGC_MAX_BYTES, 0xffffffff);
 
-  size_t availMem = op.getIntOption("available-memory");
-  if (availMem > 0) {
-    JS_SetGCParametersBasedOnAvailableMemory(cx, availMem);
+  size_t availMemMB = op.getIntOption("available-memory");
+  if (availMemMB > 0) {
+    JS_SetGCParametersBasedOnAvailableMemory(cx, availMemMB);
   }
 
   JS_SetTrustedPrincipals(cx, &ShellPrincipals::fullyTrusted);
   JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks);
   JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
   JS_SetDestroyCompartmentCallback(cx, DestroyShellCompartmentPrivate);
   JS::SetSourceElementCallback(cx, ShellSourceElementCallback);