[gjs/gnome-3-28] js: Schedule a compacting GC on gjs_gc_if_needed()



commit 70159e10dac884161f383c2611e15c9f3300bb59
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Apr 23 16:36:27 2018 +0200

    js: Schedule a compacting GC on gjs_gc_if_needed()
    
    JS_GC() during gjs regular operation will indeed end up scheduling objects
    for destruction in a timely manner. However on long lived applications
    object creation/destruction patterns may leave uneven gaps in JS heap
    arenas that get harder and harder to reuse. Side effects may include more
    expensive/infructuous GC-ing and increased memory usage.
    
    Introduce the compacting GC [1], a (slightly more expensive) GC mode that
    is able to transparently compact underused arenas. This mode does not
    happen by default, Firefox explicitly triggers it from DOM code on user
    inactivity and memory pressure situations.
    
    We can do similarly, one ideal place to call this is gjs_gc_if_needed(),
    since we are interested on the application giving up as many pages as it
    can. This keeps memory fragmentation on hold, helping gnome-shell memory
    usage stay within certain parameters on long running sessions.
    
    [1] https://hacks.mozilla.org/2015/07/compacting-garbage-collection-in-spidermonkey/
    
    [skip cpplint] because of having to include jsapi-wrapper before
    SpiderMonkey headers.
    
    https://gitlab.gnome.org/GNOME/gjs/issues/151
    
    Closes: #151
    
    (cherry picked from commit 2ee0b385e49ce6b42d2a37d862d10ba897503ae8)

 gjs/jsapi-util.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 5c91dd2a..ed3e6492 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -26,6 +26,8 @@
 
 #include <codecvt>
 #include <locale>
+#include "jsapi-wrapper.h"
+#include <js/GCAPI.h>
 
 #include <util/log.h>
 #include <util/glib.h>
@@ -34,7 +36,6 @@
 
 #include "jsapi-class.h"
 #include "jsapi-util.h"
-#include "jsapi-wrapper.h"
 #include "context-private.h"
 #include <gi/boxed.h>
 
@@ -732,7 +733,7 @@ gjs_gc_if_needed (JSContext *context)
          */
         if (rss_size > linux_rss_trigger) {
             linux_rss_trigger = (gulong) MIN(G_MAXULONG, rss_size * 1.25);
-            JS_GC(context);
+            JS::GCForReason(context, GC_SHRINK, JS::gcreason::Reason::API);
         } else if (rss_size < (0.75 * linux_rss_trigger)) {
             /* If we've shrunk by 75%, lower the trigger */
             linux_rss_trigger = (rss_size * 1.25);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]