ReviewOS

zig-utils/zig-js

Optimizer: make arrays and typed data first-class native paths

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

Parent: #459 Depends on: #469, #470, #471

Goal

Make arrays, typed arrays, DataView, and indexed loops first-class optimized native paths, including bounds-check elimination and architecture vectorization where semantics permit.

Current boundary

Packed array VM kernels own the published arrays workload before optimizer OSR. Optimizer packed reads/writes/push exist under guards, but named array properties, holes, sparse/special storage, shared mode, resizable/detachable buffers, and broader regions fall back.

Scope

  • Optimize packed/holey/sparse transitions, capacity growth, length changes, common copy/fill/map/reduce/iteration loops, and indexed property semantics with exact prototype/hook guards.
  • Add typed-array/DataView native loads/stores and conversions for all element kinds, alignment, endianness, BigInt elements, resizable/growable buffers, detach, and shared backing.
  • Use range/length proofs to eliminate redundant bounds/tag checks; add AArch64 NEON and x86 SIMD loop lowering through the common backend IR when profitable.
  • Specialize allocation/growth with failure-atomic reserve, barriers, precise roots, and bounded capacity policy.
  • Keep Array species, iterators, accessors/proxies, indexed prototype properties, holes, and user callbacks observable in exact order.

No-workaround rules

  • No treating hole as undefined, assuming a clean prototype without a versioned guard, skipping detach/resize races, weakening atomic/shared access, or retaining unbounded spare capacity.
  • Do not privilege the existing benchmark's exact 10,000-push loop.

Acceptance

  • Forced-on/off differentials cover all storage kinds, transitions, OOM, species/hooks, detach/resize, Atomics/shared memory, GC movement, and no-GIL mutation.
  • Published tier attribution moves representative array/typed-data rows from VM/general dispatch to native code.
  • Profiles show bounds/conversion/runtime-call reductions and record code size, allocation, RSS, and compilation cost.
  • SIMD/vectorized and scalar native paths have exact result/exception/memory differentials on each backend.
  • #44 arrays plus expanded #460 rows have no regression.

Foundation

#133, #448, #450–#452; packed lowering at a1307097 and reallocating push at f4916c3c.

9 days ago

Closed #529 without altering the dense Array fast path. A 15-pair exact-parent dense 4K control remained neutral at 1.001x wall, 1.008x instructions, and 1.000x peak RSS; the generic path now bounds native decimal-key storage while preserving Has/Get/Set/Delete/species semantics. Evidence.

9 days ago

Opened #676 for the TypedArray portion of the StringData audit: join separators/rendered values and toLocaleString results currently feed physical ToString bytes into canonical output buffers. The child also covers the matching String.raw and Array locale builders under #473.

9 days ago

Landed the TypedArray portion of #676 via fix(string): canonicalize ToString result builders (#676). TypedArray join and toLocaleString now append canonical WTF-8 while preserving one separator coercion, element order, resize behavior, and locale-hook count. Relevant TypedArray Test262 stayed 71/71 with 0 flips.

Sign in to comment on this issue.