ReviewOS

zig-utils/zig-js

Perf: skip GC weak passes before a realm creates weak state

#106
Closed chris opened this 9 days ago ·
9 days ago

Problem

After #105 reduced GcCellBacking.allocFn from 10,150 sampled frames to about 14, minor collection and sweep are the next object-churn costs. A fresh 8-second 8-lane sample recorded:

  • collectYoung -> sweepPhaseLocked ephemeron pass: 676 samples
  • collectYoung -> sweepPhaseLocked afterWeak pass: 327 samples
  • collectYoung young-prefix mark reset: 852 + 263 samples
  • gc.allocObjectBatch: about 1,500 samples per busy worker

The object-churn benchmark creates no WeakMap, WeakSet, WeakRef, or FinalizationRegistry state, yet zig-gc walks the managed-cell list for both weak hooks on every minor collection.

Parent: #97 Depends on: zig-utils/zig-gc#19 Related: #105

Direction

Add a realm-local monotonic false-to-true flag that is published before any weak semantic state can become collector-visible. Expose it through the zig-gc optional weak-work predicate so collections can skip ephemeron, weak-slot, and afterWeak passes while it remains false. Once true, keep using the existing conservative processing for the remainder of the Context lifetime.

Acceptance

  • Constructors/mutations that create WeakMap, WeakSet, WeakRef, or FinalizationRegistry state publish the flag before the state is visible.
  • Focused tests prove a plain realm skips weak passes and each weak feature flips the predicate without changing collection behavior.
  • Existing weak/ephemeron/finalization tests pass, including concurrent and parallel coverage under TSan where relevant.
  • Exact direct and shared 1/2/4/8 object-churn A/B retains checksum equality.
  • A material retained change refreshes README.md and the full benchmark publication.
  • Run the full suite once after the retained implementation is assembled.
9 days ago

Implementation is now on main as 6ec1fbd (perf(gc): skip weak passes before weak state (#106)).

Validation:

  • full suite: 765/765 passed, 0 skipped, 0 failed, 0 leaked
  • focused WeakMap/WeakSet/WeakRef/FinalizationRegistry coverage passed
  • concurrent WeakMap test passed under TSan
  • exact pre-hook vs current-pair A/B, matching checksums: direct object churn ~152.749 ms -> ~115.540 ms (-24.4%); shared heap 1/2/4/8 threads ~347.816/659.484/1322.397/8151.713 ms -> ~212.434/395.504/787.853/5055.409 ms (-38.9%/-40.0%/-40.4%/-38.0%).

I am running the full publication benchmark once now and will refresh README.md plus the detailed report before closing.

9 days ago

Full publication is now on main as 8dce8da (docs(bench): publish weak-pass gating results (#106)). README.md, the detailed report, and all 1,540 raw samples now describe clean implementation commit 6ec1fbd.

Published highlights:

  • direct object churn: 121.638 ms zig-js vs 118.874 ms JSC (0.98x zig-js/JSC throughput; remaining gap 2.3%)
  • exact pre-hook/current-pair A/B: -24.4% direct and -38–40% shared wall time across 1/2/4/8 lanes, matching checksums
  • versus the previous full publication: -18.5% direct; shared 1/2/4/8 lanes -38.2%/-38.4%/-40.7%/-24.3%
  • complete matrix: zig-js wins 9/10 direct rows; 2.74x direct and 2.76x warmed-eight-lane geometric-mean throughput leads
  • shared object churn remains the explicit next target, with 0.30x eight-lane scaling and high dispersion

Validation remains 765/765 tests green; the full benchmark completed all 1,540 samples and rejected no checksum or timing-floor row.

9 days ago

The first combined run for the publication exposed a real pre-existing Thread completion-ordering race in tsan-threadfuzz-midgc; it was diagnosed and tracked as #107 rather than dismissed as a flake. The fix is now on main as 044a386, with the join-focused unit and TSan families both 9/9 green. #106 remains open until the new combined run validates the complete main stack.

9 days ago

Completed by 6ec1fbd with benchmark publication 8dce8da. The follow-up completion-ordering bug exposed by CI was fixed in #107 / 044a386. The final combined main run is fully green (32 successful jobs, 0 failures): https://github.com/zig-utils/zig-js/actions/runs/29381215887.

Sign in to comment on this issue.