faster JSObjectSpace (JS runtime retain / release)#676
Conversation
|
ok, I just ran this in the ElementaryUI performance benchmark, the results are ... let's say "subtle" |
|
|
@kateinoigakukun please advise if you still want to go ahead with the |
|
@MaxDesiatov @kateinoigakukun the version currently used here (v5) does the following
limitations:
and, just for the record: using a typed array ( |
|
unfortunately, all this micro-optimizing does not fully materialize in the brower... : / here is a comparison with the current ElementaryUI benchmark script original version: current branch version: now, why this does not slash the retain times in half in the browser I don't know yet (maybe the JS engine in there applies different optimizations)? here is me thinking maybe we should stop improving this old nonsense and "just": |
|
Do you get significantly different results with different JS engines? |
|
@MaxDesiatov not really, no. but I haven't been very scientific with it. |
f1b0032 to
ec64cd5
Compare
kateinoigakukun
left a comment
There was a problem hiding this comment.
I took a time to review this but it looks good to me!
This change makes the maximum number of JSObjects that can live at the same time limited under (1 << 22) - 1 (around 4M), but it should be an acceptable constraint practically
|
LGTM, one concern from our side - we have couple of operations that traverse graphs and collect all matching nodes into an array of live JS object references. We're testing with graphs with few millions nodes, which means a single walk could hold millions of concurrent JSObjectSpace references. With SLOT_BITS = 22, the limit is ~4.19M concurrent objects. AFAIU, when you exceed it, Could we consider bumping SLOT_BITS to 24 (16M objects, 256 generations) or even 26 (64M objects, 64 generations)? The performance characteristics should be identical - it's just changing integer constants for the masks and shifts. The generation counter is a nice safety net but even 64 generations would catch the vast majority of stale ref bugs in practice 🙏🏻 |
I added a tiny benchmark to measure the
JSObjectSpacein isolation and made a few changes to speed things up.results (two example runs)
I included the benchmark script (AI slop) but I can remove it if we want a clean commit.
Also, please note that there is a behavior difference: refs are not no longer "globally unique" - ie: they will be reused once freed. a "use after free" currently causes an exception - after this PR it could now theoretically go undetected.