Offloading GC to Worker Thread in Chrome
As great as V8’s GC optimization is, given large objects and enough of them, major gc will eventually block your main thread.
Offloading GC to Worker Thread in Chrome
As great as V8’s GC optimization is, given large objects and enough of them, major gc will eventually block your main thread.
When you have a lot of TypedArray, Bitmap, OffscreenCanvas…a lot of the “Transferrable” object type, you can create a separate worker thread and at the end of your method’s scope, transfer the object’s ownership to it so that when major gc runs, it scans that thread’s heap and block it instead of the main thread.
function myFunction() {
// perhaps this is your audio processing pipeline (huge Float32Array)
// or maybe your image processing pipeline (many bitmap or canvas objects)
const arrays: Transferrable[] = await obtain();
doThing(arrays);
// here, you can either let it go out of scope or do this
gcThread.postMessage(arrays, arrays.map(a => a.buffer));
}
I mentioned “Chrome” specifically because this behavior is, as far as I know, not a part of the JS specification. And even in chrome itself, how much this helps depend largely on your hardware. For example, running this demo on my mac, it helped a lot — bumped fps back from 70 back to 120 during heavy allocations. However on my other less-powerful PC not so much. Major GC there takes so long and could not keep up with the allocation and the tab eventually dies.
Perhaps one day I will find a good use for this, but for now it remains a cool party trick (not that it’s bad!).
메타데이터
- post_id
- 2f310bca67fa
- slug
- offloading-gc-to-worker-thread-in-chrome-2f310bca67fa
- url
- https://medium.com/@khongchai/offloading-gc-to-worker-thread-in-chrome-2f310bca67fa
- canonical_url
- https://medium.com/@khongchai/offloading-gc-to-worker-thread-in-chrome-2f310bca67fa
- author_url
- https://medium.com/@khongchai
- status
- ok
- fetched_at
- 2026-06-24 11:06:28