[gjs] Ratelimit RSS-triggered GCs
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Ratelimit RSS-triggered GCs
- Date: Fri, 11 Apr 2014 18:59:39 +0000 (UTC)
commit 791b1a33424897549f487eb75a80f13c4f94437a
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Fri Apr 11 18:38:57 2014 +0200
Ratelimit RSS-triggered GCs
When loading a lot of data in memory (for example in the shell
opening the overview, which loads all the desktop files and icons)
the RSS can increase a lot, so we would trigger GCs continously
without any hope of freeing memory, so ratelimit full GCs to at
most one every 5 frames.
https://bugzilla.gnome.org/show_bug.cgi?id=728048
gjs/jsapi-util.cpp | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index b360cf2..0f62abb 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -1180,6 +1180,7 @@ _linux_get_self_process_size (gulong *vm_size,
}
static gulong linux_rss_trigger;
+static gint64 last_gc_time;
#endif
void
@@ -1190,6 +1191,13 @@ gjs_gc_if_needed (JSContext *context)
/* We initiate a GC if VM or RSS has grown by this much */
gulong vmsize;
gulong rss_size;
+ gint64 now;
+
+ /* 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)
+ return;
_linux_get_self_process_size (&vmsize, &rss_size);
@@ -1206,6 +1214,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(JS_GetRuntime(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]