ReviewOS

zig-utils/zig-js

GC compaction: evacuate fragmented tail chunks deterministically

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

Parent: #334 Contributes to: #337 Depends on: #350 Roadmap: #134

The first safe relocation path moves every eligible cell, which proves graph correctness but is not yet a useful compaction policy. Select only cells whose movement can release backing storage and publish deterministic effectiveness evidence.

Scope

  • Compute a per-size-class dense prefix after the pre-compaction sweep.
  • Pin live cells already inside that prefix and evacuate live tail cells into lower free/unissued slots.
  • Never grow backing storage merely to relocate an already-live cell.
  • Aggressively return newly emptied tail chunks after explicit compaction while retaining the ordinary collection reuse policy.
  • Add real-Context fragmentation, mixed pinned/moved, already-dense, exact-accounting, and planning-OOM witnesses.

Acceptance

  • Fragmented live heaps use fewer chunks and fewer retained capacity bytes after compaction.
  • Moved and pinned cells preserve identity/edges and exact live accounting.
  • Dense heaps report no candidates without mutation or backing growth.
  • Relocation planning OOM remains failure-atomic.
  • Focused Debug, ReleaseSafe, leak, TSan, and relocation inventory gates pass.
9 days ago

Implemented and pushed as 5243acf.

What landed:

  • computes each size class's minimal dense leading chunk prefix after the pre-move sweep
  • pins live cells already in that prefix and evacuates only tail cells
  • reserves destinations solely from lower prefix free/never-issued slots, so relocation cannot grow cell backing
  • aggressively returns every newly emptied tail chunk after explicit compaction while preserving ordinary GC's reusable-tail policy
  • records and audits the placement policy in the relocation inventory

Deterministic integration coverage creates a fragmented tail, proves mixed pinned/moved cells, fewer chunks and capacity bytes with unchanged live-slot/accounting totals, a second no_candidates fixed point, and unchanged state under scratch OOM.

Validation: focused Debug, ReleaseSafe, and TSan runs all passed 3/3 with zero leaks; the relocation inventory audit and git diff --check passed. Keeping this open until a descendant full CI run completes.

9 days ago

Completed and accepted. The implementation-specific local evidence is recorded above, and descendant full CI at https://github.com/zig-utils/zig-js/actions/runs/29716788619 completed with 42 successful jobs, one intentional nightly skip, zero failures, and zero cancellations.

Sign in to comment on this issue.