ReviewOS

zig-utils/zig-js

GC: coalesce stable identity invalidation across sweep

#1012
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Parent: #473

Measured problem

After #1011, the production representative_json invocation still performs 1,998,848 unpublication callbacks. Each callback advances GcCellBacking.stable_identity_epoch with an atomic compare/exchange, even though zig-gc already publishes exact sweep begin/end boundaries and reclaimed storage cannot be reused until per-cell finalization completes.

This is distinct from the bucket-lock telemetry: single-owner locks are already no-ops, but the epoch RMW remains real work in scored builds.

Candidate

While a sweep is active:

  1. publish a temporary cache-disabled epoch (maxInt(u64)) so stable identity always takes the exact metadata path;
  2. invalidate once at sweep begin;
  3. continue withdrawing each publication bit before finalization;
  4. invalidate once more before re-enabling range caching at sweep end.

Unpublication outside a sweep and relocation keep their immediate per-cell epoch invalidation.

A three-pair exact-parent screen against pushed #1011 produced:

  • representative_json: 0.998834x instructions, 0.978103x CPU, 0.978523x wall
  • anti-specialization variant: 0.995801x instructions, 0.988031x CPU
  • escaped strings: 0.998966x instructions, 0.985320x CPU
  • reviver source: 0.998089x instructions (CPU/wall noisy)
  • depth/shallow stringify controls: 1.001500x / 1.001416x instructions
  • all checksums exact

Definition of done

  • Pin per-cell publication withdrawal, cache-disabled exact lookup during sweep, two boundary invalidations, and immediate invalidation outside sweep.
  • Prove every successful minor/full sweep balances begin/end; aborted pre-sweep collections cannot leave caching disabled.
  • Pass focused Debug and TSan tests, conservative-root/moving-GC integration, JSON OOM/GC units, shared no-GIL TSan, and deep-input tree/VM probes.
  • Preserve JSON test262 and required VM/tree agreement.
  • Record seven interleaved exact-parent pairs with exact checksums and no hidden control regression.
  • Land as one conventional commit on main, close this issue with raw evidence, and update #473.
9 days ago

Measured and rejected; no source changes were retained.

Two formulations were tested against pushed #1011:

  1. Generic unpublication checked an atomic sweep-active flag before deciding whether to advance the epoch.
  2. The zig-gc sweep callback used an explicit sweep-only unpublication path, removing that per-cell atomic check in ReleaseFast.

The second formulation was the stronger one. Its seven interleaved exact-parent pairs are in:

/private/tmp/zig-js-json-prod.83FAYc/pairs-1012-v2-final-7/

rowcandidate / parent instructionsparent/candidate RSD
representative_json0.99789x0.38% / 0.33%
anti-specialization variant0.99826x0.40% / 0.58%
reviver source0.99998x0.65% / 0.70%
escaped strings0.99923x0.19% / 0.22%
stringify depth 40961.00122x0.61% / 0.30%
stringify shallow 40961.00107x0.11% / 0.06%
cold plain control1.00049x13.48% / 5.13%
cold Unicode control1.00956x1.21% / 0.73%

All checksums matched and thermal state remained nominal, but the result is mixed: the sustained parse rows gain only 0.08–0.21%, depth/shallow stringify regress 0.11–0.12%, and the Unicode instruction control regresses 0.96%. CPU/wall were noisy and did not establish a compensating throughput win.

The semantic prototype passed full/minor sweep balance, fail-closed pre-sweep abort/retry, and focused policy tests, but complexity without a broad measured win does not meet #473's gate. The working tree has been restored exactly to pushed 3abc2fc6.

Sign in to comment on this issue.