ReviewOS

zig-utils/zig-js

Frontend: borrow canonical oversized decimal BigInt digits

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

Parent: #496 Related: #493, #480, #544

Problem

After an oversized decimal BigInt literal fails the i128 fast path, canonicalDecimalDigits duplicates the complete digit span into the parser arena. Decimal literal validation has already rejected leading-zero forms, so an unseparated literal's source slice is canonical and immutable. A separated literal is likewise canonical after stripSeparators, which already owns its exact normalized bytes. The final duplicate therefore adds one full-width allocation and copy without changing the value.

Scope

  • Commit parser-only 1K/2K/4K unseparated decimal BigInt rows plus a separated 4K same-value control before changing the lexer.
  • Validate every canonical output byte and retain exact checksums, source construction, warmup, and timed-boundary metadata.
  • Borrow the validated source slice for unseparated oversized decimal BigInts.
  • Reuse the exact normalized buffer for separated oversized decimal BigInts.
  • Preserve small/large BigInt values, raw token text, source offsets, invalid leading-zero/separator behavior, OOM propagation, and arena lifetimes.

No-workaround rules

  • No pre-normalized scored source, source construction in the timed boundary, skipped full-value validation, reduced widths, hash/cache recognition, lazy conversion that moves work outside the boundary, or different values in the separated control.
  • No arbitrary literal-length limit and no relaxation of adversarial-complexity or memory bounds.
  • Do not modify stacks, queues, jobs, Promise/microtask behavior, or Thread/Worker lifecycle.

Acceptance

  • Benchmark-first rows freeze exact 1K/2K/4K values, same-value separated control, checksums, warmup, and parser-only timed boundaries.
  • Exact-parent evidence reports wall, retired instructions, logical allocation requests/bytes, RSS, dispersion, and identical checksums.
  • Unseparated oversized decimal BigInts allocate no canonicalization storage; separated forms retain exactly one normalization allocation.
  • Small/large values, invalid leading zeros/separators, raw text, offsets, lifetime, and OOM witnesses pass.
  • Focused lexer/frontend, full units, decimal/BigInt test262 coverage, and TSan pass with no regressions.
  • Raw evidence and report are checked in before any public performance claim.
8 days ago

Benchmark-first commit 04dd782e is on main with no runtime change.

Frozen parser-only workloads:

  • representative_frontend_bigint_decimal_1024 → checksum 1261835703
  • representative_frontend_bigint_decimal_2048 → checksum 739883633
  • representative_frontend_bigint_decimal_4096 → checksum 1770079011
  • representative_frontend_bigint_decimal_separated_4096 → the exact same value and checksum 1770079011

Source is constructed before ten reduced-work warmups. Every timed parse validates the full canonical BigInt digit sequence rather than only its length or endpoints. The ReleaseFast runner builds and all twelve initial smoke samples retain exact workload identity and checksum.

8 days ago

Completed and pushed to main:

  • 04dd782e bench(frontend): add decimal BigInt width rows (#545)
  • f91369c6 perf(frontend): borrow canonical decimal BigInts (#545)
  • e1debe62 docs(frontend): publish decimal BigInt evidence (#545)

The checked aggregate report links all four raw artifacts and per-row reports.

Seven order-balanced exact-parent pairs show that every row removes exactly one logical allocation request per parse. Unseparated allocation bytes fall 45.2%, 58.1%, and 71.5% at 1K/2K/4K; the separated same-value 4K control falls 39.0% while retaining its one exact normalization allocation. Wall medians remain within 2.1% and peak-RSS ratios remain below 1.0. The stable unseparated 4K row's visible +1.9% wall result is retained, so the report claims no material wall change rather than a speedup.

Correctness and safety gates:

  • focused TSan: 1/1 pass, no leaks
  • lexer: 14/14 pass; focused frontend: 12/12 pass
  • full sharded units: 1,609 pass, 1 intentional skip, 0 fail, 0 leak
  • exact-parent test262: BigInt literals 59 → 59 passing; numeric literals 157 → 157 passing; 0 flips
  • zero-capacity source borrowing, exact one-allocation separated normalization, canonical value, pointer identity, lifetime, and OOM witnesses pass
  • all four raw artifacts validate against zig-js-performance-attribution-v1

Sign in to comment on this issue.