ReviewOS

zig-utils/zig-js

Perf: use precise GC checkpoints for materialized quick loops

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

Parent: #62 Related: #97, #49, #44

Evidence

An 8-second sample of the frozen clean direct object_churn binary shows the fixed-shape quick loop dominating execution. Within GC work, root tracing repeatedly spends time in Visitor.markConservativeWord; stale native-stack words can also conservatively retain/promote dead young cells and increase later old-space work.

The fixed-shape object quick loop is a special safe case: its checkpoint-crossing path already writes the live accumulator/IP to the registered Exec, and the loop writes the array, displaced value, numeric temporaries, fresh object, total, and counter into registered frame slots before the ordinary checkpoint service runs. The helper has returned before advanceQuickObservableSteps services the checkpoint, so no helper-only GC pointer remains live solely in a native local.

Scope

  • Mark only the materialized fixed-shape loop's normal checkpoint crossing as precise.
  • At that checkpoint, trace registered Context/Interpreter/Exec/frame roots but skip the conservative native-stack scan.
  • Preserve conservative scanning for generic VM/tree-walker/native/error paths and for every parallel collector path.
  • Add focused proof that the precise marker is scoped/restored and a nursery collection at such a checkpoint preserves the exact live graph.
  • Measure frozen-binary order-balanced A/B for direct and warmed eight-context object churn; shared mode must remain byte-identical/unaffected.

Acceptance

  • Improve direct and warmed-independent object churn without checksum or semantic changes; do not regress other benchmark rows.
  • Preserve exact step/safepoint counts, OOM/termination behavior, GC reachability, weak/finalization behavior, and all generic conservative-scan coverage.
  • Pass focused VM/GC tests and the final batched normal/TSan gates.
  • Publish clean full-matrix results and update README/docs only after all gates pass.
9 days ago

Implemented and published on main.

The change scopes precise root tracing to private (vm.gil == null) fixed-shape quick-loop checkpoints after the helper has materialized its accumulator, instruction pointer, and frame values into registered roots. Generic VM/tree-walker/native/error paths and all shared/GIL paths retain conservative native-stack scanning. The discriminator is per interpreter rather than process-global, so a threaded context created earlier cannot change later private-context behavior.

Focused proof covers forced minor collection across 4,096 object replacements, exact arena-vs-GC output, collection/counter evidence, scope restoration, and the shared-path exclusion. The fixed-shape focused group passed 5/5 with no leaks.

Frozen order-balanced direct object-churn A/B:

  • baseline-first: 135.834 ms -> 111.581 ms (17.9% faster)
  • candidate-first: 118.177 ms -> 112.118 ms (5.1% faster)
  • exact checksum: 1,030,552,128

Eight-context warmed and shared checks were neutral within run-order variance and preserved exact checksums. The clean full publication now wins the direct object-churn comparison at 114.315 ms versus JSC's 119.322 ms. Remaining independent-context and shared-realm object-churn work stays tracked by #62, #97, and #116.

Final batched gates:

  • normal: 767/767 passed, 0 skipped/failed/leaked
  • TSan: 766 passed, 1 expected skip, 0 failed/leaked, no sanitizer report
  • benchmark publication guards: 7/7 passed
  • docs: 24 pages rendered successfully

Closing once the two main CI runs for the implementation and publication commits finish green.

9 days ago

Authoritative main CI is green: https://github.com/zig-utils/zig-js/actions/runs/29431577221 completed with 32 successful jobs, 1 expected skip, 0 failures, and 0 cancellations on publication commit 1d76bfa0. All #118 implementation, semantic, local normal/TSan, publication, documentation, and hosted integration criteria are satisfied. Remaining multi-context/shared object-churn work continues in #62, #97, and #116.

Sign in to comment on this issue.