ReviewOS

zig-utils/zig-js

Intl.DisplayNames: reuse static cells for resolved enum fields

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

Parents: #475, #479 Related: #460, #461, #493, #603, #604

Problem

IntlDisplayNamesData already stores style, kind, fallback, and languageDisplay as closed native enums. Intl.DisplayNames.prototype.resolvedOptions() converts those enums back to byte slices and allocates fresh managed StringCells for every result object.

Unlike the already measured Collator, DurationFormat, DateTimeFormat, and NumberFormat reflection paths, DisplayNames has no dedicated committed resolved-options workload. This issue is benchmark-first so the observable work and checksum are frozen before the runtime changes.

Scope

  • Add a representative DisplayNames resolved-options row that reuses the existing eight immutable formatter fixtures, creates a fresh result per operation, and consumes every present field, key count, spelling byte, formatter identity, and lane contribution.
  • Add exact Value projections for every DisplayNames Style, Kind, Fallback, and LanguageDisplay enum case using immutable static StringCells.
  • Keep locale dynamically owned and managed.
  • Preserve ECMA-402 field presence/order, conditional languageDisplay, brand checks, constructor option observation, OOM atomicity, moving/parallel GC, and formatter output.

No-workaround rules

  • Do not cache/reuse observable result objects, omit unread fields, recognize benchmark source/name, precompute scored results, or globally intern attacker-controlled strings.
  • Do not touch Promise, microtask, Worker, Thread lifecycle, stacks, queues, or jobs code.

Acceptance

  • Benchmark source, formatter identities, key inventory, jobs, checksum, warmup, and timed boundary land before the runtime fix.
  • Each emitted enum value is the exact unmanaged static cell; locale stays managed.
  • Exact cell/backing reductions match the emitted three-or-four-enum field count with identical execution, Shape requests, and checksum.
  • Exact test262 DisplayNames coverage has zero flips/regressions.
  • Focused normal/TSan, bounded/moving/parallel GC, OOM, and full sharded unit gates pass.
  • Order-balanced timing is reported; no broad claim is made from a focused row.

Security boundary

Options and call frequency are attacker-controlled. The change must project only validated enum state and retain managed ownership for dynamic locale bytes; no mutable global cache or permissive fallback is allowed.

9 days ago

Benchmark-first parent landed on main in 103413d0 (bench(intl): add DisplayNames resolved options row (#605)).

The frozen row reuses the existing eight formatter fixtures, creates 6,400 fresh result objects per 100 jobs, and consumes key count plus every present field spelling, formatter identity, loop index, and lane contribution. Three independent ReleaseFast samples retain checksum 193486270.

Exact parent invocation: 244,802 managed cells, 446,413 backing allocations, 27,201 tree-walker entries, and 27,200 Shape requests. Full benchmark-comparison validation passes, including 18/18 structural gates. No runtime code changed and this commit flips 0 test262 cases.

9 days ago

Runtime implementation is complete on main in 3b61ee05 (perf(intl): reuse static DisplayNames options (#605)), following the frozen benchmark parent 103413d0.

All Style, Kind, Fallback, and LanguageDisplay enum cases now project through exact immutable static StringCells. Locale remains dynamically owned/managed and each fresh result object plus conditional field presence/order is unchanged.

Exact 6,400-operation evidence:

  • managed cells: 244,802 -> 224,002 (-20,800)
  • GC cell bytes: 34,816,512 -> 33,485,312 (-1,331,200)
  • backing allocations: 446,413 -> 425,613 (-20,800)
  • execution and Shape requests: identical
  • checksum: 193486270 before and after

Twenty-one order-balanced pairs are wall-neutral: 195.639667 ms -> 195.434750 ms (-0.105%), 14/21 candidate wins. The result is therefore an allocation/lifetime improvement only, not a throughput claim.

Validation:

  • exact test262 DisplayNames: 57/57 pass before and after, 0 failures/flips
  • all 13 enum spellings plus dynamic locale ownership: normal and TSan pass
  • focused bounded/native-thread/generated-data/OOM group: 8/8 pass
  • full units: 1,721 passed, 1 skipped, 0 failed, 0 leaked

Sign in to comment on this issue.