Friday, August 19, 2022

Garbage Collection in JavaScriptCore

Haoran Xu:

The garbage collector in JSC is non-compacting, generational and mostly–concurrent. On top of being concurrent, JSC’s GC heavily employs lock-free programming for better performance.

[…]

The inlined metadata cellState is easy to access for the mutator thread (the thread executing JavaScript code), since it is just a field in the object. However, it has bad memory locality for the GC and allocators, which need to quickly traverse through all the metadata of all objects in some block owned by CompleteSubspace (which is the common case). Outlined metadata have the opposite performance characteristics: they are more expensive to access for the mutator thread, but since they are aggregated into bitvectors and stored in the block footer of each block, GC and allocators can traverse them really fast.

So JSC keeps both inlined and outlined metadata to get the better of both worlds: the mutator thread’s fast path will only concern the inlined cellState, while the GC and allocator logic can also take advantage of the memory locality of the outlined bits isNew and isMarked.

All this engineering notwithstanding, I still find myself using Chrome for some sites like Board Game Arena, where performance, even with an M1 Mac, is abysmal compared with Chrome on a much slower Mac.

Previously:

Comments RSS · Twitter

Leave a Comment