ReviewOS

zig-utils/zig-js

Perf: defer object-loop numeric frame writes

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

Parent: #62

Problem

The guarded fixed-shape object-allocation loop keeps its numeric counter and total in native locals, but still boxes and writes both values back to Frame.slots after every fused iteration. A quick batch executes at most the remaining checkpoint budget and has no safepoint after a successful replacement; the frame only needs the completed values when the batch exits. Allocation and restricted-receiver error paths must continue to expose the exact last completed state.

Proposed change

  • keep counter and total in native locals throughout the quick batch
  • write their boxed frame values once after at least one completed iteration
  • flush the last completed values before propagating allocation or restricted-receiver errors
  • preserve bytecode step accounting, observable side exits, overflow fallback, and checksum behavior

Acceptance

  • focused quick object-loop tests cover isolated/shared parity, checkpoint batching, guarded fallback, and observable error paths
  • exact checksum remains 1030552128
  • exact-parent alternating object_churn A/B shows a repeatable improvement
  • full unit and benchmark-harness validation is batched only if retained
  • revert and close as not planned if neutral or slower
9 days ago

Implemented and pushed to main in 94078ba.

The quick object-allocation loop now keeps counter and total native for the fused batch, boxes them once on normal exit, and explicitly flushes the last completed state before both allocation and restricted-receiver errors.

Validation:

  • focused fixed-shape allocation filter: 3/3 passed, zero leaks
  • focused quick-object replacement filter: 3/3 passed, zero leaks
  • full units: 760/760 passed, zero leaks
  • comparison harness: 7/7 passed

Exact-parent A/B against a9523889:

  • 14 alternating process pairs
  • 3 samples per process
  • candidate wins: 11/14
  • median of process medians: parent 209.388 ms, candidate 205.826 ms
  • paired median change: approximately -1.38%
  • first batch: 6/7 wins
  • confirmation batch: 5/7 wins
  • exact checksum 1030552128 throughout

Direct candidate/JSC check under the same loaded host:

  • five alternating process pairs, three samples per process
  • zig-js median: 200.419 ms
  • JSC median: 121.009 ms
  • remaining direct gap: approximately 1.656x
  • exact checksum throughout

Commit authorship is Chris chrisbreuer93@gmail.com with no coauthors.

Sign in to comment on this issue.