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.
This commit is contained in:
Avi Halachmi (:avih)
2020-03-27 18:33:20 +03:00
committed by Tor Andersson
parent ed33bc01d5
commit c4c1524e97
2 changed files with 7 additions and 4 deletions

10
jsgc.c
View File

@@ -130,8 +130,8 @@ void js_gc(js_State *J, int report)
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 @@ void js_gc(js_State *J, int report)
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 @@ void js_gc(js_State *J, int report)
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);
}
}

View File

@@ -38,6 +38,7 @@ static js_Property *newproperty(js_State *J, js_Object *obj, const char *name)
node->getter = NULL;
node->setter = NULL;
++obj->count;
++J->gccounter;
return node;
}