Skip to content

Reudce GC timings by simplifying the tracing logic and optimising BlockList

Yorick Peterse requested to merge reduce-gc-timings into master

e0a458d4 - Simplify tracing code to improve performance

In commit 347ade20 a new approach to tracing objects was introduced, improving performance in the process. This implementation used a "busy" counter to terminate tracer threads when all work was complete.

While the approach was correct, it was not efficient. When there is little work to do, threads would spin for much longer than needed, as all threads observing "busy" to be 0 could take a while based on timings and bad luck. In various cases this meant tracing would take 20-30 milliseconds, even though all work was done in less than 5 milliseconds.

In this commit we greatly simplify the tracing approach by just letting threads terminate when they run out of work, regardless of the number of busy workers. In some rare cases this may result in threads terminating prematurely, but for all tests we ran so far this has not proven to be a problem. In fact, the current approach drastically cuts down garbage collection timings, and makes the tracing code much simpler.

f2f7283e - Use a Vec for BlockList

The BlockList type now stores (and owns) blocks in a Vec, while still linking them together using a "next" pointer. This requires minimal changes to the allocator, while allowing one thread to iterate the list of blocks (using the "next" pointers) while allowing another thread to add new values. This also allows the collector to more efficiently iterate over the blocks when preparing and reclaiming blocks.

Another benefit is that appending BlockList types is much faster, as we no longer need to iterate over all the blocks to append. This can drastically reduce garbage collection timings.

Fixes #180 (closed)

Edited by Yorick Peterse

Merge request reports