ReviewOS

zig-utils/zig-js

Intl: reuse static ListFormat and RelativeTimeFormat options

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

Parents: #475, #479 Related: #460, #461, #493, #605

Problem

IntlListFormatData stores type/style as closed native enums and IntlRelativeTimeFormatData stores style/numeric as closed native enums. Both resolvedOptions() paths currently turn those enum values back into bytes and allocate fresh managed StringCells on every call.

Neither service has a dedicated resolved-options performance row. This issue freezes one combined reflection workload before changing the runtime.

Scope

  • Add immutable formatter matrices spanning all ListFormat type/style and RelativeTimeFormat style/numeric cases.
  • Add a representative row that creates fresh resolved-options objects for both services per operation and consumes every present field, key count, spelling byte, formatter identity, loop index, and lane contribution.
  • Project the four closed enums through exact immutable static StringCells.
  • Keep locale and RelativeTimeFormat numberingSystem dynamically owned and managed.
  • Preserve ECMA-402 field order/presence, brand checks, constructor option observation, OOM atomicity, moving/parallel GC, and formatting output.

No-workaround rules

  • No cached/reused result objects, skipped unread fields, source/name recognition, precomputed scored results, or global interning of dynamic strings.
  • Do not touch Promise, microtask, Worker, Thread lifecycle, stacks, queues, or jobs code.

Acceptance

  • Benchmark identities, fields, checksum, warmup, jobs, and timed boundary land before runtime changes.
  • Every enum spelling is the exact unmanaged static cell; dynamic locale/numbering strings remain managed.
  • Exact allocation reduction is four enum cells per scored pair with identical execution, Shape requests, and checksum.
  • Exact test262 ListFormat and RelativeTimeFormat coverage has zero flips/regressions.
  • Focused normal/TSan, bounded/moving/parallel GC, OOM, and full sharded units pass.
  • Paired timing is reported without a broad claim from the focused row.

Security boundary

Options and call frequency are attacker-controlled. Only constructor-validated closed enum state may become static; dynamic locale/numbering bytes retain their existing ownership and GC contract.

9 days ago

Benchmark-first parent landed on main in 338b472b (bench(intl): add list and relative reflection row (#606)).

Eight immutable formatters per service cover all ListFormat type/style and RelativeTimeFormat style/numeric values. Each 100-job invocation creates 6,400 fresh result objects per service and consumes every field, key count, formatter identity, loop index, and lane contribution. Three ReleaseFast samples retain checksum 975333233.

Exact parent invocation: 444,002 managed cells, 811,213 backing allocations, 44,801 tree-walker entries, and 44,800 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 7f46c2dd (perf(intl): reuse static list and relative options (#606)), following frozen benchmark parent 338b472b.

ListFormat type/style and RelativeTimeFormat style/numeric now project through exact immutable static StringCells. Locale and numberingSystem remain managed, and result-object creation plus field order is unchanged.

Exact paired 6,400-operation evidence:

  • managed cells: 444,002 -> 418,402 (-25,600)
  • GC cell bytes: 62,566,912 -> 60,928,512 (-1,638,400)
  • backing allocations: 811,213 -> 785,613 (-25,600)
  • execution/Shape requests: identical
  • checksum: 975333233 before and after

Twenty-one order-balanced pairs are wall-neutral: 317.699333 ms -> 317.838250 ms (+0.044%), 8/21 candidate wins. Only the allocation/lifetime improvement is claimed.

Validation:

  • exact test262 ListFormat: 81/81 before and after
  • exact test262 RelativeTimeFormat: 80/80 before and after
  • all 11 enum spellings plus dynamic locale/numbering ownership: normal and TSan pass
  • focused service OOM/native-thread plus bounded/moving/parallel structural groups pass
  • the first full run hit an unrelated scheduler-sensitive optimized-read test with a numeric zero-check result; it then passed 5/5 focused and the clean full rerun passed 1,722, skipped 1, failed 0, leaked 0

Sign in to comment on this issue.