ReviewOS

zig-utils/zig-gc

Perf: batch owned-cell unpublication during sweep

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

Downstream: zig-utils/zig-js#97

Evidence

The current sweep releases equal-size storage in 64-cell batches, but it first calls unpublishCellAllocation once per dead cell. In zig-js that acquires the same size-class lock for every bitmap removal, then freeCellStorageBatch reacquires it once for the matching free-bitmap run. The shared object_churn workload produces long runs of same-size dead Object cells, and the latest eight-lane sample still shows serialized sweep/backing-bitmap work after publication batching.

The atomic-header-guard experiment in #31 did not pass the downstream gate. This issue keeps exact bitmap ownership and instead batches the existing lock-protected state transition.

Design

  • Add an optional unpublishCellAllocationBatch binding hook with a per-cell fallback.
  • In sweep, identify a bounded consecutive run of same-size white cells, unpublish the complete run under one binding lock, then finalize, unlink, unindex, poison, and release it in the existing order.
  • Never batch across an alive cell, allocation size, young-generation boundary, or collection boundary.
  • Preserve the invariant that no cell is finalized or returned to reuse while its owned-storage classifier still reports it published.

Acceptance criteria

  • Exact owned-storage tests prove a same-size dead run uses one unpublication batch and remains unclassified before reuse.
  • Mixed live/dead types and minor/full collection accounting and finalization order remain exact.
  • Full zig-gc normal suite and focused zig-js parallel-GC semantic gate pass.
  • On an order-balanced exact-parent zig-js object_churn A/B, do not regress 1/2 lanes and materially improve 4 and 8 lanes; otherwise fully revert and document the result.
9 days ago

Rejected after the exact downstream performance gate; the prototype has been fully reverted in both repositories.

Correctness before measurement:

  • full zig-gc suite passed;
  • exact backing-lock proof passed 2/2;
  • focused zig-js parallel-GC gate passed 5/5 with no leaks;
  • every benchmark checksum matched the exact parent.

Order-balanced seven-pair ReleaseFast zig-js shared object_churn A/B, 100 jobs:

lanesparent medianbatched-unpublish mediandelta
1107.140 ms102.990 ms-3.87%
2215.825 ms207.807 ms-3.71%
4701.952 ms729.188 ms+3.88%
81424.305 ms1450.002 ms+1.80%

Although the implementation removes per-cell ownership-bitmap locking during sweep, it fails the explicit no-regression/material-improvement contract at both high-contention lanes. This reinforces that ownership bitmap transitions are not the governing 4/8-lane bottleneck; the next experiment needs to remove or parallelize collector traversal/global publication work rather than further batch the existing sweep tail.

No README score was changed because this was not an accepted full matrix.

Sign in to comment on this issue.