ReviewOS

zig-utils/zig-js

Perf: recycle non-escaping VM call activations

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

Parent: #48

Profile evidence

A symbolized GC-enabled Fibonacci run executes bytecode. The hot path included vm.runChunk, buildActivation, and repeated global identifier lookup. buildActivation retained a new Activation, Frame, local slot buffer, operand stack backing, and handler backing in the Context arena for every call.

A 1,000-job diagnostic reached 11 GiB physical footprint with a 28.4 GiB reported peak before throwing. On an identical 50-job process run, the cached baseline consumed 3.36 GiB maximum RSS.

Scope

  • Reuse completed VM activations only when their frame did not escape into a closure.
  • Retain operand/handler capacity and reset all logical state before reuse.
  • Never recycle a captured frame or expose pooled stale values to GC tracing.
  • Release activations on return, tail-call replacement, unwind, and error teardown paths.
  • Add a focused bounded-allocation regression plus closure and deep-recursion coverage.
  • Measure process-isolated before/after Fibonacci time and RSS.
  • Run focused semantic/GC/no-GIL/TSan checks, commit with issue references, and push to main.
  • Require the final combined Actions gate to pass.

Result

Implemented in eda34f5. Seven process-isolated 20-job samples improved from a 486.112 ms median to 409.844 ms (1.186x). The 50-job optimized run used 6.9 MiB maximum RSS versus 3.36 GiB for the cached baseline.

9 days ago

Implemented and pushed in eda34f5 (refs #48 and #51).

Evidence:

  • Seven process-isolated 20-job samples: 486.112 ms baseline median → 409.844 ms optimized median (1.186x).
  • Identical 50-job process: 3.36 GiB → 6.9 MiB maximum RSS; timed work 1.244 s → 1.039 s.
  • Checksums unchanged.
  • Focused bounded-allocation, closure, deep-recursion, parallel-GC, and TSan checks passed.
  • Reduced cross-engine comparison matrix passed every checksum group.

The full Actions run from the push remains the final closure gate.

9 days ago

Final combined gate passed: 31 jobs succeeded, zero failed, and the nightly-only job was skipped as expected. https://github.com/zig-utils/zig-js/actions/runs/29280193748

Sign in to comment on this issue.