ReviewOS

zig-utils/zig-gc

Perf: batch owned cell release after sweep finalizers

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

Problem

Sweep currently finalizes, unlinks, and returns each dead cell through std.mem.Allocator.free. Owned slab embedders therefore repeat allocator-vtable dispatch, size classification, ownership lookup, and synchronization for every reclaimed nursery cell. A current zig-js object_churn profile attributes a large share of minor sweep time to this path.

Proposed API

Add an optional Binding batch-release contract. When present, the collector will:

  • finalize and unlink white cells exactly as today;
  • retain dead headers in a collector-private intrusive list;
  • begin one release phase only after every finalizer has completed;
  • hand each allocation base and exact byte size to the Binding;
  • end the release phase after the batch.

Bindings without the complete hook retain byte-for-byte generic allocator frees.

Acceptance criteria

  • Generic allocator and finalizer semantics remain covered.
  • A focused owned-storage test proves finalizers precede the release phase and no per-cell backing free occurs.
  • Minor and full collection accounting remains exact.
  • Full zig-gc tests pass.
  • Downstream zig-js implements the hook and shows a repeatable order-balanced object_churn improvement before either commit is retained.

Downstream: zig-utils/zig-js#62

9 days ago

Rejected and fully reverted after downstream pinned A/B. The post-finalizer batch form measured 246.774375 ms versus 246.042625 ms baseline (+0.30%, 2/7 pair wins). A second immediate comptime-owned-release form removed the deferred pass but measured 247.623791 ms versus 245.197667 ms baseline (+0.99%, 3/7 pair wins). Each protocol used seven order-balanced fresh-process pairs, three timed samples per process, and exact checksum 1030552128 in all 42 samples. Full zig-gc tests and focused downstream tests were green, but neither design met the performance gate, so no commit was retained.

Sign in to comment on this issue.