ReviewOS

zig-utils/zig-js

Intl.DateTimeFormat: compile immutable resolved formatting state

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

Parent: #475 Depends on: #528, #563

Goal

Compile each Intl.DateTimeFormat instance's validated locale, calendar, numbering-system, hour-cycle, style expansion, and component selection into one immutable formatter-owned native record, so steady consumers do not repeatedly traverse and reinterpret the engine's internal options object.

Current boundary

dtfStoreOptions normalizes constructor input into an internal \x00opts object, but dtfBuildParts performs generic property reads for every component on every format, formatToParts, formatRange, and formatRangeToParts call. It also re-expands date/time styles and re-derives hour behavior on the steady path.

This issue owns resolved-state compilation and lookup only. Direct text emission, locale pattern coverage, range interval data, and numeric scratch allocation are separate slices so their effects remain independently measurable.

Scope

  • Add frozen construction and steady-state controls spanning default/component/style, locale/calendar/numbering-system/hour-cycle, Temporal input, parts, and range consumers.
  • Store one immutable native resolved record with explicit GC ownership and relocation/destruction handling.
  • Compile style expansion and invariant formatter decisions once, while preserving the per-input Temporal component restrictions required by ECMA-402.
  • Make all DateTimeFormat consumers read the native record without generic internal property traversal.
  • Preserve resolvedOptions, legacy chaining, Date.prototype.toLocale*, subclassing, Proxy/getter order at construction, OOM failure atomicity, and shared-realm read-only use.

No-workaround rules

  • No service-name/source/workload recognition, hidden preformatting, unbounded process-global cache, ICU/system-JSC dependency, English-only bypass, skipped observable option access, or duplicated formatter algorithm.
  • No raw pointers into movable GC storage; every borrowed slice in the record needs a stable ownership ruling.
  • No weakening locking, GC barriers, OOM behavior, or Temporal/date semantics to improve a benchmark.

Acceptance

  • Benchmark boundary records deterministic construction and steady text/parts/range controls with exact zig-js/JSC checksums.
  • Steady consumers perform zero generic reads from the internal normalized options object.
  • The resolved record has explicit moving-GC, destruction, OOM, bounded-heap, and no-GIL ownership tests.
  • Focused DateTimeFormat and Temporal test262 subtrees, full Intl402, full unit, TSan, no-GIL, and movement gates pass.
  • Exact-parent evidence reports wall time, retired instructions where available, backing allocations/bytes, and construction non-regression.
9 days ago

Benchmark boundary landed in 0d95d623. Eight 250-job construction/consumer controls use full-string checksums and match system JSC exactly. Parent zig-js medians: text 263,807,916 ns; parts 1,011,420,667 ns; equal-range 304,225,208 ns; equal-range-parts 1,606,277,625 ns. Invocation snapshots record 1,123,299 / 5,563,230 / 1,123,260 / 9,099,244 backing allocations and 2,004,246 / 6,376,150 / 2,252,150 / 10,880,150 generic object-property acquisitions. Constructor controls remain separately frozen and are already faster than JSC, so the implementation must preserve that boundary.

9 days ago

Completed on main in 939d9394.

DateTimeFormat now publishes one compact immutable native resolved record after specification-ordered option observation. Reflected fields remain distinct from construction-time style expansion; six potentially movable locale/calendar/numbering/hour-cycle/time-zone slices share one formatter-owned allocation with explicit OOM rollback and GC destruction. format, parts, equal-range consumers, resolvedOptions, Date locale methods, and Temporal locale methods no longer traverse an internal options object.

Exact-parent medians improve text to 0.968x, parts to 0.923x, equal-range to 0.900x, equal-range-parts to 0.987x, and the four construction controls to 0.933x-0.965x. Constructor backing allocations fall 4.5%-9.9% and GC cells 7.2%-8.8%; backing bytes remain flat/lower except +0.034% on the locale row.

Verification:

  • all eight full-string benchmark checksums exactly match system JSC;
  • DateTimeFormat test262: 244 -> 244 (0 flips);
  • Temporal test262: 4,603 -> 4,603 (0 flips);
  • full Intl402: 3,341/3,341;
  • full units: 1,656 pass / 1 skip / 0 fail / 0 leak;
  • focused normal and TSan: bounded reclamation, exhaustive OOM publication, moving nursery, and four-lane no-GIL sharing all clean.

Sign in to comment on this issue.