ReviewOS

zig-utils/zig-js

Intl.DateTimeFormat: project resolved field enums through static cells

#603
Closed chris opened this 10 days ago ·
10 days ago

Parents: #475, #479 Related: #461, #493, #602

Problem

IntlDateTimeFormatData.Field is already a closed native enum whose string() method returns one of the ECMA-402 fixed field/style names. Intl.DateTimeFormat.prototype.resolvedOptions() currently turns those enum values back into byte slices and allocates a managed StringCell for every non-empty component and style on every call.

The existing representative_intl_date_time_format_construct_components row performs 3,200 constructor + resolvedOptions() operations per 100 jobs. On current main (e9d641d3), its exact invocation delta after warmup is 140,817 managed-cell allocations and 265,626 backing allocations with checksum 914,759,620. This issue will isolate the enum projections inside that unchanged workload.

Scope

  • Add an exact Value projection for every non-empty IntlDateTimeFormatData.Field case using immutable static StringCells.
  • Use that projection for resolved component names and dateStyle / timeStyle only; locale, calendar, numbering-system, time-zone, and other dynamically owned strings remain on their existing path.
  • Preserve ECMA-402 property presence and insertion order, component/style exclusivity, exact bytes, forced-GC lifetime, and all constructor option-observation behavior.
  • Measure exact-parent cell/backing allocation deltas and order-balanced paired timing on default, component, style, and locale constructor rows.

No-workaround rules

  • Do not cache or reuse the observable resolved-options object, skip fields the benchmark does not read, recognize benchmark source/name, intern attacker-controlled strings globally, or weaken GC ownership.
  • Do not touch Promise, microtask, Worker, Thread lifecycle, stacks, queues, or jobs code.

Acceptance

  • Every emitted Field value is the exact unmanaged static cell for its spec spelling; .none remains absent.
  • The existing workload keeps identical work, option objects, property order, and checksum while exact cell/backing allocations fall by the predicted number of emitted enum strings.
  • Exact test262 DateTimeFormat coverage has zero flips/regressions.
  • Focused normal/TSan, bounded/moving GC, and full sharded unit gates pass.
  • Paired timing and allocation evidence are recorded even if the wall result is neutral; no broad performance claim is made without evidence.

Security boundary

Option objects and call frequency are attacker-controlled. The optimization must only project validated closed enum state and must not introduce mutable global caches, lifetime ambiguity, or any fallback from dynamic string ownership.

10 days ago

Implemented and pushed to main in 10ac2f3d (perf(intl): reuse static resolved field strings (#603)).

IntlDateTimeFormatData.Field now projects every non-empty ECMA-402 component/style spelling through its exact immutable static StringCell; .none remains absent. Dynamic locale, calendar, numbering-system, time-zone, and other owned strings are unchanged.

Exact 3,200-operation allocation evidence:

  • default: 124,808 -> 115,208 managed cells (-9,600; 3 per operation)
  • components: 140,817 -> 118,417 (-22,400; 7 per operation)
  • style: 124,812 -> 118,412 (-6,400; 2 per operation)
  • locale: 156,815 -> 147,215 (-9,600; 3 per operation)
  • component GC cell bytes: 18,638,656 -> 17,205,056 (-1,433,600)
  • component backing allocations: 265,626 -> 243,226 (-22,400)

Execution counters, Shape requests, and frozen checksums are identical. In 21 order-balanced component-row pairs, median wall time is 81.766750 ms -> 79.220792 ms (-3.114%), with 21/21 candidate wins. The other rows range from -0.280% to +0.307%, so no broad throughput claim is made.

Validation:

  • exact test262 DateTimeFormat: 244/244 pass before and after, 0 failures/flips
  • all 11 spellings: exact unmanaged cell identity before and after forced GC; normal and TSan pass
  • focused DateTimeFormat bounded/moving/parallel/OOM group: 9/9 pass
  • full units: 1,719 passed, 1 skipped, 0 failed, 0 leaked

Sign in to comment on this issue.