ReviewOS

zig-utils/zig-js

Perf: retain fixed-shape allocation quickening in shared realms

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

Parent: #97 Related: #62

The shared-realm object_churn row falls back to the generic VM because the existing fixed-shape allocation loop rejects parallel IC mode. Sampling the exact eight-lane row shows Heap.headerForPayload and Heap.create dominating, plus substantial lock waiting. The fallback also makes one shared lane several times slower than one direct context before scaling is considered.

Scope:

  • allow the established fixed-shape allocation loop to execute when parallel IC synchronization is active;
  • resolve literal shapes through seqlock reads without mutating the isolated-mode prepared-shape cache;
  • snapshot displaced elements and properties under their shared locks;
  • publish replacements with an exact owner/child barrier and an element-lock presence check;
  • preserve generic [[Set]] fallback if a concurrent exotic mutation invalidates the dense store;
  • keep escaped frames and unsupported shapes on ordinary bytecode.

Acceptance:

  • Preserve exact results and bytecode steps between isolated, synchronized, and fallback execution.
  • Add a real multi-Thread regression using one shared compiled chunk and lane-local rings.
  • Preserve Object.prototype identity, proxies/accessors/descriptors, restricted receivers, OOM state, barriers, and GC tracing.
  • Show repeatable exact-parent wins in shared one-lane and eight-lane object_churn without regressing direct mode.
  • Pass focused semantic/GC/no-GIL tests, full units once, and relevant TSan CI.

Initial exact-parent evidence after the implementation:

  • shared one lane: 704 ms to 200 ms median (-71.6%), candidate won 7/7 alternating pairs;
  • reduced eight lanes: 1.98 s to 0.93 s (-52.9%), candidate won 7/7;
  • direct: 254 ms to 222 ms (-12.7%), candidate won 6/7;
  • all checksums exact.
9 days ago

Implemented and pushed in b8a4973; the complete comparison evidence/README refresh is 6b27f4d.\n\nExact-parent alternating A/B (seven process pairs, lower is better):\n- direct, 100 jobs: 254.325 ms -> 222.126 ms median (-12.66%), candidate won 6/7 pairs\n- shared, 1 lane x 100 jobs: 704.202 ms -> 199.675 ms (-71.65%), 7/7\n- shared, 8 lanes x 10 jobs: 1,977.723 ms -> 932.142 ms (-52.87%), 7/7\n- all checksums matched exactly\n\nCorrectness/validation:\n- fixed-shape quickening and restricted-receiver focused tests pass in isolated and shared modes\n- real four-Thread shared-realm regression records >3,000 quick-loop hits and exact results\n- both focused TSan cases pass\n- full unit suite: 761/761, zero leaks\n- comparison harness: 7/7\n- docs build: 24 pages\n- full fair comparison: 1,540 validated raw samples, every median over 50 ms\n\nThe clean-commit full report moved shared object churn from the prior 986.746/28,321.516 ms one/eight-lane result to 488.792/18,472.129 ms. #97 remains open because allocation/collector serialization still makes mode-local scaling only 0.21x.\n\nFresh main CI: https://github.com/zig-utils/zig-js/actions/runs/29359544830 (a newer docs push may supersede this run). Leaving this issue open until the current main TSan jobs complete.

9 days ago

Current combined implementation + documentation main run: https://github.com/zig-utils/zig-js/actions/runs/29360393347 (queued). This supersedes the implementation-only run cancelled by the documentation push.

9 days ago

The shared fixed-shape quick path is now exercised by the batch-publication consumer in 84d2f9f4: the real four-Thread test still requires >3,000 quick hits and now also proves >=2,048 cells flow through batched publication. Focused normal and TSan tests passed, followed by 761/761 full units with zero leaks.

The exact-parent benchmark preserved direct throughput (-1.25% elapsed median) and improved shared 8-lane elapsed time by 56.42% in alternating A/B. The latest publication is in 3cc2a58c.

Keeping #98 open until the superseding main CI run completes: https://github.com/zig-utils/zig-js/actions/runs/29364341824

9 days ago

Superseding main CI is green on attempt 2: https://github.com/zig-utils/zig-js/actions/runs/29364341824

Relevant gates all passed:

  • 4/4 normal unit shards
  • 4/4 TSan unit shards
  • tsan-parallel-js
  • 4/4 TSan no-GIL corpus shards
  • default/broad/amplified/lifecycle/mid-GC threadfuzz and TSan variants
  • comparison harness and docs

The one first-attempt serialized OOM witness miss is isolated separately in #100; its failed-only 58-case shard rerun passed and is unrelated to the shared fixed-shape quickening acceptance. Closing #98.

Sign in to comment on this issue.