ReviewOS

zig-utils/zig-js

Perf: keep fixed object-allocation loop integers unboxed

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

Parent: #62

Evidence

Current main after the 512-byte Object slab still trails system JSC on the fair direct object_churn row: 241.143 ms versus 127.080 ms median-of-process-medians across seven alternating process pairs with three samples per process, a 1.898x remaining elapsed gap. Checksum 1030552128 matched in every sample.

A symbolized 1 ms profile of the current ReleaseFast runner attributes 96 exclusive samples to Value.toNumber and 83 to Value.toInt32. The guarded fixed-object allocation loop currently rebuilds Value.num(counter) for selector/stamp conversion and routes the already-numeric checksum through generic coercion on every optimized iteration.

Scope

  • require and retain an exact non-negative integer counter/increment representation in the structural fixed-object allocation loop;
  • compute bitwise selector and stamp values from the guarded integer representation without transient Value boxing;
  • add an already-number fast ToInt32 path for checksum values when the exact conversion is provably equivalent;
  • fall back before mutation for unsupported counter representations and retain the full numeric conversion for checksum edge cases;
  • preserve exact VM step/checkpoint accounting, OOM state publication, GC roots/barriers, and all observable object/array guards.

Acceptance criteria

  • Focused tests prove the fast path stays active for exact counters and falls back for fractional/negative/out-of-range counters.
  • Differential execution preserves results and exact bytecode-step counts.
  • Existing accessor/proxy/indexed-store fallback coverage remains green.
  • Order-balanced exact-parent A/B shows a repeatable improvement with stable checksums.
  • Full validation is batched with the retained implementation.
  • Retained commits reference this issue.
9 days ago

Implemented and pushed to main in a9523889.

The structural fixed-object allocation tier now guards and retains an exact u32 counter/increment, derives selector and stamp bitwise values without transient Value boxing, and uses a numeric-only ToInt32 path for the checksum. Fractional, negative, and greater-than-32-bit counters fall back before mutation; other checksum edge cases retain the full ECMAScript numeric conversion.

Exact-parent ReleaseFast evidence used two independent seven-pair alternating batches, three timed samples per fresh process:

  • combined result: 11/14 pair wins;
  • median paired elapsed change: -4.38%;
  • checksum 1030552128 in every sample.

Same-window candidate versus system JSC:

  • zig-js: 223.980 ms;
  • JSC: 131.320 ms;
  • remaining direct gap: 1.706x.

Validation:

  • focused optimized/fallback/differential test passed after the final rebase;
  • 760/760 unit tests passed with zero leaks;
  • 7/7 benchmark-harness tests passed.

Sign in to comment on this issue.