Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 52 min read Deep dive hardMaster

Understanding Garbage Collection in JavaScriptCore From Scratch

JavaScriptCore's garbage collector is non-compacting, generational and mostly concurrent, with heavy use of lock-free programming. The explanation starts from a naive stop-the-world generational collector and adds pieces one at a time until it reaches JSC's real design. Along the way it covers BlockDirectory-based allocators (CompleteSubspace, PreciseAllocation, IsoSubspace), why per-object metadata is split between an inlined cellState and outlined isNew/isMarked bitvectors, and how write barriers and remembered sets keep marking correct. For incremental and concurrent collection it adds remembered-set scheduling and Space-Time Scheduler mitigations, which address up to 5x memory blowup.

Related posts

  • Introducing the JetStream 3 Benchmark Suite

    WebKit hardMaster

    JetStream 3 replaces JetStream 2's separate Wasm Startup/Runtime scores with the JavaScript-style first-iteration, worst-case and average-case scoring. The old scheme broke once engines hit sub-millisecond startup that Date.now() rounded to zero, giving infinite scores. The suite also favors larger workloads over microbenchmarks. WebKit details the JavaScriptCore work behind its results. Inlining WasmGC object fields into one allocation gave about 40% on the WasmGC subtests, and removing per-object destructors gave about 40% on Dart-flute-wasm. Other work inlines bump-pointer allocation into the BBQ and OMG tiers, uses Cohen's display for constant-time subtype checks, makes priority-based non-local inlining decisions, and profiles indirect calls for guarded inlining.

  • Size-Specialized Memory Allocation

    The Go Blog hardMaster

    Go 1.27 adds size-specialized variants of the runtime's mallocgc for allocations of 80 bytes or fewer, one per span class (size class plus pointer/no-pointer), making these allocations 20-30% faster and allocation-heavy programs up to 1% faster. The compiler calls a specialized function directly when the size is known at compile time; otherwise mallocgc dispatches to it dynamically. Most of the gain comes from clearing memory with constant-size inline instructions instead of calling memclrNoHeapPointers, plus precomputed span classes, cheaper pointer bookkeeping and forced inlining. The functions are produced by a go/ast-based generator to keep copies in sync, and the 80-byte cutoff balances speed against binary size and instruction cache pressure. It can be disabled with GOEXPERIMENT=nosizespecializedmalloc.

  • Oilpan library · V8

    V8 hardMaster

    Oilpan, the trace-based C++ garbage collector originally built for Blink, has been extracted into a library hosted in V8 since v9.4 (enabled in Chromium M94) under the cppgc namespace. It marks precisely on the heap and conservatively on the native stack, supports concurrent/parallel marking and sweeping plus compaction, and can run stand-alone (as PDFium does for XFA) or as part of V8's unified JavaScript/C++ heap. Moving it out of Blink cut a ~30k-target build down to seconds for its 400+ unit tests, and V8 now steers embedders off the EmbedderHeapTracer API toward allocating C++ objects on an Oilpan heap attached to an Isolate.

  • Adventures in Garbage Collection: Improving GC Performance in our Massive Monolith

    Shopify Engineering hardMaster

    Shopify cut Ruby garbage-collection tail latency in its monolith by finding why major GCs were triggered, via GC.latest_gc_info(:major_by), and removing each cause in turn. Major marks took over 4 seconds, and most were triggered by the oldmalloc limit, so the team effectively disabled it. They then preallocated slots per size pool for Ruby 3.2's variable width allocation, since deploys every 30 minutes kept processes in warm-up. They also added write barriers to Ruby core types and gems, cutting shady objects from about 160,000 to about 3,000. Finally, out-of-band major GC every 128–512 requests cut p99.9/p99.99 GC time by about 10x and nearly eliminated GC pauses for median requests, with the warning never to tune GC without first measuring the impact.

  • Bun 1.4

    Bun mediumAdept

    Bun 1.4 adds 1,517 newly passing Node.js test-suite tests, fixes over 2,900 issues, and rewrites Bun from Zig to Rust. JavaScriptCore now uses an extended mimalloc instead of libpas, adding a scavenger thread, partial page clearing and better lazy zeroing. Together with GC timer tuning, segmented-array Strong roots and fewer futex calls, this cuts idle CPU 5x, HTTP server peak memory 13–48%, and Linux startup time in half. New APIs include Bun.Image, Bun.WebView, Bun.markdown, Bun.cron and Bun.Terminal, plus Markdown CPU, heap and bundle profiles and a cross-platform memoryPressure event built on kqueue, PSI and Windows resource notifications.

The quest for software engineering knowledge.

Look:
Layout: