ReviewOS

zig-utils/zig-js

Perf: remove unused slab free-node magic writes

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

Parent: #62

Evidence

The current ReleaseFast object_churn profile attributes 187 exclusive samples to GcCellBacking.freeFn, making per-cell slab reclamation one of the largest remaining local costs. Every reclaimed cell currently writes a 24-byte FreeNode containing magic, next, and chunk_idx.

free_slot_magic is never read by allocation, ownership classification, trimming, GC, or production diagnostics. Its sole reader is one unit-test assertion. The collector already clears its authoritative header magic before returning the slot, and slab ownership/counters provide the allocator invariants.

Scope

  • remove the unused free-node magic field and constant;
  • retain the next pointer and chunk index required by reuse/live-count accounting;
  • update focused allocator coverage to assert the actual reusable metadata and behavior;
  • keep slab alignment, ownership, trimming, reuse, statistics, parallel locking, and delegated side allocations unchanged.

Acceptance criteria

  • Focused GcCellBacking tests pass with zero leaks.
  • Reclaimed slots still reuse correctly and preserve chunk live/free counters.
  • Exact-parent alternating object_churn A/B shows a repeatable improvement with stable checksums.
  • Full validation is batched if the change is retained.
  • Retained commits reference this issue.
9 days ago

Experimented locally and rejected; no commit was created.

Implementation:

  • removed the private free_slot_magic field/write
  • reduced FreeNode from 24 bytes to 16 bytes
  • replaced the sentinel-only assertion with assertions for the consumed next and chunk_idx metadata

Correctness:

  • focused GC cell backing suite: 19/19 passed, zero leaks

Exact-parent A/B on object_churn:

  • parent: a9523889
  • 14 alternating process pairs
  • 3 samples per process
  • exact checksum 1030552128 throughout
  • candidate wins: 9/14
  • median of process medians: parent 209.667 ms, candidate 208.981 ms
  • paired median change: approximately -0.31%
  • first batch: 6/7 candidate wins
  • confirmation batch: 3/7 candidate wins

The change saves one store but does not reduce slab memory because the size classes are fixed. The confirmation batch did not reproduce the initial signal and the combined effect is within observed process noise, so this does not meet the retention bar. The source was fully reverted and the worktree is clean.

Sign in to comment on this issue.