ReviewOS

zig-utils/zig-gc

Perf: let owned cell backings classify conservative interior roots

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

Downstream: zig-utils/zig-js#62 Related: #4

Problem

Visitor.markConservativeWord lazily rebuilds and sorts a live-cell extent index on the first conservative word of every collection, then binary-searches it for every scanned stack word. That generic fallback is necessary for arbitrary backing allocators, but an embedder with exact slab/chunk ownership already has a persistent address index and can classify an interior address without walking or sorting the live-cell list.

The post-optimization zig-js object_churn profile shows the generic index sort (sort.block) at 98 top-of-stack samples and conservative lookup at 73 samples during repeated nursery collections.

Design

  • add an optional binding hook returning a tri-state conservative classification: outside owned storage, owned but not a live payload candidate, or exact allocation base;
  • validate header magic and the exact payload extent inside zig-gc before marking;
  • allow a binding with compile-time-proven all-owned cell storage to reject outside addresses without building the generic index;
  • retain the current lazy sorted-index path unchanged for bindings without the hook or with delegated cells;
  • expose the exact cell allocation byte count needed for downstream compile-time size proofs.

Acceptance criteria

  • Exact payload and interior pointers in owned slabs mark their live cell.
  • Header, padding, unissued, freed, and unrelated addresses reject safely.
  • Generic/delegating bindings retain the existing sorted-index fallback.
  • A proven all-owned binding never builds the generic address index during conservative scanning.
  • Full zig-gc tests pass and downstream profile materially improves.
9 days ago

Implemented and pushed directly to main in 51c491e.

The heap now exposes InteriorOwnership, optional binding hooks for conservative interior classification and complete owned-cell coverage, and a public cellAllocationBytes helper. Owned bindings can return outside, owned_empty, or an exact allocation base; the collector still validates header magic and exact payload extent. Bindings without the hook retain the generic lazy sorted address index.

Validation:

  • zig-gc: 26/26 tests passed
  • owned-backing tests cover header, payload, interior, end, owned-empty, outside, and prove the generic index remains unbuilt
  • downstream zig-js integration: zig-utils/zig-js#66, commit ecd5bb4
  • downstream zig-js suite: 752/752 plus 7/7 benchmark harness tests
  • downstream clean A/B object-churn reduction: 13.3 percent

Acceptance criteria are met.

Sign in to comment on this issue.