shithub: libmujs

Download patch

ref: c4c1524e97a99e06acb8382a7d325ce99bf553f9
parent: ed33bc01d5f4e9a736830d706371163ab2db8e5a
author: Avi Halachmi (:avih) <avihpit@yahoo.com>
date: Fri Mar 27 14:33:20 EDT 2020

gc: don't ignore property allocations count

They're not negligible in the overall count.

This decreases the performance of scripts which use objects with many
properties because the GC threshold remains the same (10K) but it's
reached quicker due to counting more allocations, so GC is more
frequent and wastes more overall time.

Good example of the performance impact is the splay.js v8 bench test,
where this commit reduces its score by a factor of 5.

We're not changing the threshold because it's arbitrary anyway, but the
next commit will change it in a way which allows more proportional
control of the GC overhead.

--- a/jsgc.c
+++ b/jsgc.c
@@ -130,8 +130,8 @@
 	js_Object *obj, *nextobj, **prevnextobj;
 	js_String *str, *nextstr, **prevnextstr;
 	js_Environment *env, *nextenv, **prevnextenv;
-	int nenv = 0, nfun = 0, nobj = 0, nstr = 0;
-	int genv = 0, gfun = 0, gobj = 0, gstr = 0;
+	int nenv = 0, nfun = 0, nobj = 0, nstr = 0, nprop = 0;
+	int genv = 0, gfun = 0, gobj = 0, gstr = 0, gprop = 0;
 	int mark;
 	int i;
 
@@ -212,8 +212,10 @@
 
 	prevnextobj = &J->gcobj;
 	for (obj = J->gcobj; obj; obj = nextobj) {
+		nprop += obj->count;
 		nextobj = obj->gcnext;
 		if (obj->gcmark != mark) {
+			gprop += obj->count;
 			*prevnextobj = nextobj;
 			jsG_freeobject(J, obj);
 			++gobj;
@@ -238,8 +240,8 @@
 
 	if (report) {
 		char buf[256];
-		snprintf(buf, sizeof buf, "garbage collected: %d/%d envs, %d/%d funs, %d/%d objs, %d/%d strs",
-			genv, nenv, gfun, nfun, gobj, nobj, gstr, nstr);
+		snprintf(buf, sizeof buf, "garbage collected: %d/%d envs, %d/%d funs, %d/%d objs, %d/%d props, %d/%d strs",
+			genv, nenv, gfun, nfun, gobj, nobj, gprop, nprop, gstr, nstr);
 		js_report(J, buf);
 	}
 }
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -38,6 +38,7 @@
 	node->getter = NULL;
 	node->setter = NULL;
 	++obj->count;
+	++J->gccounter;
 	return node;
 }