[gjs] jsapi-util: Also rate limit checking the process size



commit f7a571cbc5ea3d0737565139290f9ee81a369ed8
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Aug 8 20:53:50 2017 +0200

    jsapi-util: Also rate limit checking the process size
    
    Querying /proc/self/stat has quite an overhead which e.g. can be seen
    when draging a window. Before this patch the GC was already rate
    limited to only run every 5 frames. This also lowers the rate of
    checking whether the GC should be run to be lower.
    
    This change may delay a GC run a bit. However the maximum delay is
    equivalent to the previous rate limiting.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786017

 gjs/jsapi-util.cpp |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index bbec8d5..0dfe12f 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -706,7 +706,7 @@ _linux_get_self_process_size (gulong *vm_size,
 }
 
 static gulong linux_rss_trigger;
-static gint64 last_gc_time;
+static int64_t last_gc_check_time;
 #endif
 
 void
@@ -722,9 +722,11 @@ gjs_gc_if_needed (JSContext *context)
         /* We rate limit GCs to at most one per 5 frames.
            One frame is 16666 microseconds (1000000/60)*/
         now = g_get_monotonic_time();
-        if (now - last_gc_time < 5 * 16666)
+        if (now - last_gc_check_time < 5 * 16666)
             return;
 
+        last_gc_check_time = now;
+
         _linux_get_self_process_size (&vmsize, &rss_size);
 
         /* linux_rss_trigger is initialized to 0, so currently
@@ -740,7 +742,6 @@ 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);
-            last_gc_time = now;
         } 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]