ReviewOS

zig-utils/zig-js

Perf: retain prepared literal shapes in object-allocation plans

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

Problem

The fixed-shape object-allocation quick plan persists for the lifetime of its bytecode Chunk, but every safepoint-bounded re-entry repeats three literal inline-cache transition lookups and prepareInlineLiteralShape validation. object_churn re-enters roughly every 16 iterations to preserve exact 1024-step safepoints, so this immutable work recurs throughout the hot loop.

A current symbolized profile still shows prepareInlineLiteralShape after #74. The prepared descriptor is already documented as valid for the owning Context lifetime because Shape parent, name, and slot metadata never mutate.

Parent: #62

Proposed slice

  • Store one prepared literal descriptor and its root-shape key in QuickObjectAllocationLoop.
  • Reuse it only in isolated execution and only when the current root shape matches.
  • On a different realm root, rerun all current IC and chain validation before replacing the cache.
  • Keep shared or escaped execution on the existing fallback path.

Acceptance criteria

  • A test-only preparation counter proves a multi-safepoint object loop prepares once, while existing exact-step and guarded-fallback assertions remain green.
  • Order-balanced fresh-process object_churn A/B preserves checksum 1030552128 and shows a repeatable improvement.
  • Full units and benchmark harness pass before a small conventional commit is pushed to main.
9 days ago

Landed on main in a8f6931. The persistent quick plan now caches the validated three-property literal descriptor by exact realm root shape, so each safepoint-bounded re-entry avoids three repeated IC transition lookups and the immutable shape-chain validation. The focused 96-iteration test proves more than one quick batch executes while preparation occurs exactly once; shared mode still rejects the path. Seven order-balanced fresh-process pairs with three timed samples per process measured baseline 269.520000 ms versus candidate 251.106333 ms median-of-process-medians, 6.832% less elapsed time (1.0733x throughput), with 6/7 pair wins and checksum 1030552128 in all 42 samples. Full validation passed 759/759 units with zero skips, failures, or leaks plus 7/7 benchmark-harness tests. The absolute host was noisy, so this is paired optimization evidence rather than final JSC publication evidence.

Sign in to comment on this issue.