ReviewOS

zig-utils/zig-js

VM: quicken computed numeric TypedArray stores

#1046
Closed chris opened this 8 days ago ·
8 days ago

Parent: #498 Related: #1045, #493, #473

Problem

VM set_index specializes existing dense Array elements, but primitive Number keys on TypedArrays always stringify through ToPropertyKey and re-enter generic Integer-Indexed Exotic [[Set]]. Unlike object/string/Symbol keys, a Number key has no user-visible key coercion. The existing TypedArray store routine already owns the difficult semantic requirement: coerce the RHS first, then revalidate the buffer and index because coercion may resize or detach the backing buffer.

A pre-fix VM witness matches Node across valid, numeric -0, invalid/fractional/NaN/infinite/large indices, object and string keys, Number/BigInt coercion, and shrink/grow/detach during valueOf; the test-only typed-store fast-hit count remains zero.

Scope

  • Add a VM set_index fast path for primitive Number keys on direct TypedArray receivers.
  • Reuse the canonical Number/BigInt coercion and post-coercion buffer/index revalidation path.
  • Preserve numeric -0 → index zero, invalid-index RHS coercion, resizable/detached/immutable behavior, and restriction checks.
  • Keep object, Symbol, and string key coercion on the generic ToPropertyKey + [[Set]] path.
  • Update the source-derived quickening inventory and generated architecture page.

Acceptance

  • The pre-fix witness changes from zero to a positive typed-store fast-hit count with identical Node results.
  • Number and BigInt values, invalid indices, dynamic shrink/grow/detach, object keys, and string "-0" are pinned.
  • Focused normal and unsuppressed TSan tests pass.
  • Quickening inventory, benchmark-validator, docs-manifest, and offline-link gates pass.
  • No duplicated coercion semantics, benchmark recognizer, or unsynchronized backing-store access.
8 days ago

Implemented and pushed in 52614c1e.

Primitive Number keys on direct TypedArray receivers now bypass property-key string allocation in VM set_index. The fast path roots receiver and RHS across user code, checks restriction ownership, and delegates Number/BigInt conversion plus post-conversion index/buffer validation to the existing Interpreter.taStore path. Numeric -0 maps to element zero; invalid numeric indices still coerce the RHS; shrink, growth, detach, and wrong BigInt value types retain their canonical behavior. String, Symbol, and object keys remain on full ToPropertyKey + [[Set]].

Evidence:

  • pre-fix VM witness: identical semantics, zero typed-store fast hits
  • after fix: identical semantics, positive fast hits; Node agrees on the full edge matrix
  • focused VM and unsuppressed TSan: 4/4 each
  • quickening inventory validation/self-test: 17 guarded families and five explicit unsupported families
  • benchmark harness validators: 19/19
  • docs: 51 pages with exact manifest; 378 offline links

The local Test262 corpus is unavailable, so no Test262 flip count is claimed.

Sign in to comment on this issue.