ReviewOS

zig-utils/zig-js

Intl.DateTimeFormat: reuse identical range endpoints

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

Problem

After #572 and #573, Intl.DateTimeFormat.prototype.formatRange(x, x) still builds the same formatted endpoint twice and then discovers that every emitted value is equal. formatRangeToParts(x, x) likewise duplicates the structural build before returning the first endpoint with source: "shared".

The retained representative controls intentionally use equal endpoints and currently attribute, at 100 jobs:

  • range text: checksum 552787875, 460,782 cumulative backing allocations, 90,431,085 backing bytes, 234,716 GC cells, 8 collections;
  • range parts: checksum 789386393, 3,651,166 cumulative backing allocations, 480,804,917 backing bytes, 2,025,117 GC cells, 73 collections.

Scope

  • Preserve the specified left-to-right conversion of both arguments before any identity decision.
  • Recognize only identical canonical legacy time values and identical immutable Temporal object identities as a one-endpoint case.
  • Build direct text once for formatRange and structural parts once for formatRangeToParts in that case.
  • Retain the existing two-endpoint structural comparison for distinct values that merely format alike or need interval collapse.
  • Preserve TimeClip errors, Temporal kind/calendar checks, part boundaries/source attribution, OOM propagation, moving-GC safety, and read-only no-GIL sharing.
  • Measure exact-parent text/parts controls and run DateTimeFormat plus Temporal conformance, focused normal/TSan/no-GIL, and full units.

Out of scope

  • New CLDR interval patterns or collapse rules.
  • Value comparison across distinct Temporal objects.
  • Promise/microtask/Worker/job lifecycle work.

Parent: #475 Depends on: #573

9 days ago

Landed on main in perf(intl): reuse identical DateTimeFormat ranges (#574).

Both inputs remain coerced left-to-right and kind/calendar checks run before reuse. Equal canonical numbers or the same immutable Temporal identity build once; distinct values retain the full interval/collapse behavior. Equal invalid infinities still coerce both inputs before RangeError.

Exact-parent evidence:

  • range checksums match the exact parent and system JSC: text 552787875, parts 789386393
  • text medians are 0.927x and 0.933x in opposite-order 11-sample windows
  • range-text cumulative backing bytes fall 90,431,085 -> 80,576,073 (-10.9%)
  • GC cells remain 234,716 -> 234,716; collections remain 8 -> 8
  • range-parts native backing bytes fall 480,804,917 -> 480,780,437; the dominant JS part-object work is unchanged

Verification:

  • DateTimeFormat: 244/244
  • Intl402 Temporal: 2,029/2,029
  • built-ins Temporal: 4,603/4,603
  • affected flips: 0
  • focused TSan: 7/7, including moving GC and no-GIL coverage
  • full units: 1,658 pass / 1 skip / 0 fail / 0 leak
  • format and diff checks clean

Sign in to comment on this issue.