ReviewOS

zig-utils/zig-js

Wasm: execute atomics natively and scale shared memory

#490
Open chris opened this 9 days ago ·
9 days ago

Parent: #486 Depends on: #487, #476, #478, #482

Goal

Execute Wasm shared-memory atomics and wait/notify natively and remove engine/runtime scaling bottlenecks while preserving the exact Wasm threads memory model.

Measured boundary

The July 18 report records eight-worker contended add at 1.18x scaling, disjoint add at 1.25x, contended CAS at 0.54x, and 287,444 wait/notify pair handoffs/s after a nonmonotonic four-worker peak. Multi-worker timing includes shared-realm Thread construction and joins.

Scope

  • Lower every supported atomic load/store/RMW/CAS/fence/wait/notify operation to correct target atomics with exact width, alignment, sign, bounds, and ordering.
  • Separate unavoidable cache-line contention from interpreter dispatch, address/bounds checks, shared-instance locks, waiter-table locks, Thread lifecycle, parking, and wake storms.
  • Optimize disjoint accesses, waiter sharding, generation/queue bookkeeping, park/wake handoff, false sharing, and bounded waiter cleanup.
  • Preserve memory growth synchronization, instance/module sharing, spurious wake/timeouts, termination, and JS Atomics interoperability.
  • Add fixed-thread steady-state panels alongside lifecycle-inclusive public Thread panels, clearly labeled.

No-workaround rules

  • No relaxed memory order in place of required semantics, non-atomic fast path, changed contention layout, omitted lifecycle from an existing row, busy-spin presented as wait performance, or JSC comparison where no equivalent public surface exists.

Acceptance

  • All threads corpus atomics execute through verified native attribution on each backend.
  • Exact memory-model litmus, bounds/alignment/trap, growth race, wait/notify/timeout/termination, no-GIL, TSan, and lifecycle gates pass.
  • Profiles identify and materially reduce engine overhead in disjoint/CAS/wait rows; unavoidable hardware contention is reported separately.
  • Scaling is monotonic where work is disjoint, lifecycle and steady-state metrics are both retained, and RSS/waiter resources stay bounded.
  • Dated raw evidence replaces the July 18 artifact only after clean full validation.

Foundation

#284–#288; current 105-sample report.

9 days ago

The shared Wasm/typed-array wait domain was hardened in #862 via fix(atomics): seed shared waiter domains (#862). Exact WaitKey semantics and FIFO behavior are unchanged; bucket placement is now process-secret and failure-atomic under the existing mutex. Both nonzero Wasm waiter unit gates pass, including shared-memory growth/store destruction, and the no-GIL typed-array witness remains green.

Sign in to comment on this issue.