Skip to content

[JSC] Name one time zone without listing every zone, and hold it as ICU's zone object - #1086

Open
robobun wants to merge 2 commits into
mainfrom
robobun/f699561e/time-zone-holder-and-per-name-ids
Open

robobun wants to merge 2 commits into
mainfrom
robobun/f699561e/time-zone-holder-and-per-name-ids

Conversation

@robobun

@robobun robobun commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • The first local-time read of a Date takes 38.7 million instructions and 520 page faults, for every TZ. Bun: 2.5 ms. Node: 0.05 ms. @sosukesuzuki asked for this fix, which finishes VM: skip eager timezone prewarm under USE(BUN_JSC_ADDITIONS) #322.
  • Naming the host's zone builds a table of every zone: 21 million instructions. DateCache then opens a UCalendar for the zone, which loads ICU's likely-subtags data: 18 million.

Fix

  • Commit 1: TimeZoneRegistry numbers zones as the process names them, and asks ICU about one name.
  • Commit 2: ICUTimeZone holds a zone as an icu::TimeZone at the three calendar sites. Darwin keeps the UCalendar.
  • Bun, TZ set: 2.50 ms to 0.02 ms, 487 faults to 4. 802 TZ values give identical output.
  • Verified: 9 new JSTests, 1 testaot test, JSTests --quick, bun's time zone tests under LeakSanitizer. Self-reviewed: 30 concerns raised, 29 addressed.

Background

  • ICU's C API has no zone object, only a calendar. icu::TimeZone is in its C++ API, which WebKit hides.
  • Two choices need a maintainer's yes: the fork's first use of ICU's C++ API, and a registry that threads read without a lock. Each commit lands alone.
  • Considered an ICU patch (Calendar::setWeekData) that keeps the calendar: 236 thousand instructions for the first read, against 106 thousand, and no per-call gain.

Downsides

  • An alias, another case or an invalid name lists ICU's zone names once: 1.9 million instructions (main: 21 million).
  • Not fixed: TZ unset with a regular-file /etc/localtime, and the first Intl.DateTimeFormat (32 million instructions).
  • No CI lane runs these tests on macOS or Windows.
Notes

How the numbers were made

  • Linux x64, Debian 13, ICU 79.1 as bundled. jsc and bun are release builds without LTO. "main" is cbf8d97, which is Bun's WEBKIT_VERSION and the base of this branch. bun is 7bb427f3b in every column.
  • Instructions are user instructions of the whole process (perf_event_open, all threads), median of 21 runs for a first read and of 5 to 9 runs elsewhere. A first read is new Date(1700000000000).getHours() over the same script with getUTCHours().
  • Times are 40 interleaved runs of each binary. Main against main differs by 0.004 ms.

First local-time read

jsc, instructions / minor page faults:

TZ main commit 1 commits 1 and 2
unset 38,651,503 / 519 17,656,954 / 493 91,734 / 22
UTC 38,651,357 / 519 17,645,966 / 488 69,780 / 24
America/Los_Angeles 38,667,174 / 527 17,673,463 / 490 106,231 / 23
US/Pacific 38,672,167 / 518 17,686,515 / 489 111,374 / 22
Asia/Calcutta 38,661,438 / 517 17,679,255 / 492 100,852 / 22
EST5EDT 38,686,041 / 519 17,704,107 / 493 115,530 / 22
america/los_angeles 38,964,180 / 528 19,499,958 / 507 1,946,885 / 41
Invalid/Zone 38,978,922 / 530 19,472,196 / 507 1,922,295 / 39
:/etc/localtime 38,956,158 / 526 19,477,905 / 508 1,915,845 / 40

bun, the same read. Instructions / faults over the getUTCHours() script, and the time of the read in the process:

TZ main this PR
unset 39,142,794 / 492 / 2.555 ms 80,160 / 15 / 0.055 ms
UTC 39,071,627 / 485 / 2.510 ms 40,207 / 3 / 0.016 ms
America/Los_Angeles 39,075,054 / 487 / 2.498 ms 42,477 / 4 / 0.020 ms
Asia/Calcutta 39,053,863 / 486 / 2.520 ms 52,439 / 4 / 0.022 ms
america/los_angeles 39,388,605 / 486 / 2.557 ms 1,931,633 / 30 / 0.144 ms
Invalid/Zone 39,387,222 / 484 / 2.535 ms 1,906,983 / 24 / 0.136 ms
  • Whole process with TZ unset: bun 5.77 ms to 3.24 ms, jsc 4.79 ms to 2.94 ms.
  • node v26.3.0 on this machine: 0.051 to 0.055 ms, 15 to 18 faults.
  • A process that reads no local time enters no zone function and costs the same: jsc 2,786,766 and 2,785,293 instructions, bun 3,928,173 and 3,932,316.
  • Not changed: bun with TZ set does about 210 thousand instructions more at its start than with TZ unset (4,139,658 against 3,928,173), before any Date. Skip the walk over live Dates at a time zone change when no Date has cached a local time bun#46614 is about that.

What ICU does on the first read

Entries of ICU functions while jsc runs the getHours() script (gdb breakpoints with ignore counts):

initLikelySubtags TZEnumeration::create ucal_open ucal_getIanaTimeZoneID
main, every TZ 1 2 1 611
commit 1, America/Los_Angeles 1 0 1 2
commit 1, america/los_angeles 1 1 1 2
both, TZ unset 0 0 0 1
both, America/Los_Angeles 0 0 0 2
both, america/los_angeles 0 1 0 2

First use of other entry points

jsc, TZ=America/Los_Angeles, instructions over an empty script:

first operation of the process main commit 1 both
new Date(0).getHours() 38,689,949 17,694,317 113,261
new Date(0).toString() 39,219,902 18,212,864 659,228
Temporal.Now.timeZoneId() 38,672,666 17,677,547 107,857
Temporal.Now.zonedDateTimeISO().hour 38,702,244 17,707,981 142,523
Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO("Asia/Tokyo").hour 38,681,780 17,663,863 89,193
new Temporal.ZonedDateTime(0n, "America/New_York").hour 38,667,414 17,659,899 75,654
new Intl.DateTimeFormat().resolvedOptions() 53,159,311 32,463,622 31,987,541
new Intl.DateTimeFormat("en", { timeZone: "America/New_York" }).format(0) 52,635,562 31,986,420 31,538,486
new Date(0).toLocaleString() 53,319,802 32,482,817 32,203,232
Intl.supportedValuesOf("timeZone") 21,158,299 20,921,014 20,913,703

The first Intl.DateTimeFormat formats for a locale, so it still loads the likely-subtags data. About 11 million of the rest is the set of available locales (intlDateTimeFormatAvailableLocales), which converts every locale of ICU to a language tag.

First use of names, over a script with a ZonedDateTime of an offset. No JIT, so that no helper thread compiles the loop of the script:

names main this PR
UTC 21,098,450 39,798
one primary identifier 21,125,646 87,017
8 primary identifiers 21,300,784 502,459
200 primary identifiers 22,054,571 6,994,717
all 445 primary identifiers 22,415,614 14,639,170
an alias (US/Pacific) 21,090,074 1,935,670
all 154 aliases 21,652,786 9,645,124
another case (america/new_york) 21,395,952 1,922,731
a name that is no zone 21,400,742 1,893,838
all 638 names of ICU, once each 23,465,481 22,587,891
supportedValuesOf 21,154,760 20,923,919
supportedValuesOf, then all 638 23,585,991 22,728,351
an alias, then supportedValuesOf 21,241,105 20,975,768
200 primary identifiers, then supportedValuesOf 22,129,332 21,928,143
all 638, then supportedValuesOf 23,585,310 22,958,984

A primary identifier costs about 30 thousand instructions the first time, an alias up to 60 thousand. No order of names costs more than main.

Per call, after the first use

Instructions per iteration, from runs of N and 2N iterations with --useConcurrentJIT=0:

main commit 1 both
new Temporal.ZonedDateTime(0n, "+05:00") (no name) 781 781 781
new Temporal.ZonedDateTime(0n, name), 8 primary names 1,608 1,204 1,204
the same with an alias 2,046 1,169 1,169
the same in another case 2,117 1,169 1,170
zoned.timeZoneId 257 236 236
a.equals(b) 339 303 303
a name that ICU does not list (throws) 5,907 5,060 5,061
"PST", which ICU lists and which is no zone (throws) 5,874 4,968 4,968
"SystemV/PST8" (throws) 5,948 5,305 5,306
new Intl.DateTimeFormat("en", { timeZone }) 202,677 202,362 202,148
new Intl.DateTimeFormat("en", { timeZone: "PST" }) (throws) 10,327 9,395 9,334
new Date(t).getHours(), t 20 days on each time 2,928 2,928 2,130
new Date(y, m, d).getTime(), 20 days on each time 2,946 2,957 2,608
instant.toZonedDateTimeISO(name).offsetNanoseconds 3,556 3,077 2,274
  • JSTests/microbenchmarks/temporal-zoned-date-time-time-zone-cache.js: 4,389.2, 4,368.5 and 2,423.8 million instructions (252, 255 and 157 ms).
  • temporal-zoned-date-time-from-named-time-zone.js: 408.8, 388.5 and 280.1 million (30.6, 28.4 and 22.4 ms).
  • A change of process.env.TZ and a local read in bun, per change: 263,988 to 234,387 instructions. The change alone is 210,465 and 210,478.

The registry is read without a lock

Upstream's table is built once and then read without a lock. The registry grows, and keeps that property: TimeZoneRegistry::resolve() and zone() have no lock prefix, and on the path of a hit they call a hash and a compare. new Temporal.ZonedDateTime(0n, name) in 1, 4 and 8 threads of one process: 1,534, 1,540 and 1,541 instructions a call on main, 1,137, 1,136 and 1,138 here.

Wall time per call in each thread, jsc, median of 7 runs:

main this PR this PR with a WTF::Lock and a HashMap as the registry
new Temporal.ZonedDateTime(0n, name), 1 thread 63.0 ns 53.9 ns 54.9 ns
the same, 8 threads 66.2 ns 58.8 ns 3,210 ns
zoned.timeZoneId, 1 thread 8.2 ns 7.4 ns 16.1 ns
the same, 8 threads 9.8 ns 8.9 ns 200.3 ns
a.equals(b), 1 thread 18.0 ns 16.5 ns 35.4 ns
the same, 8 threads 21.8 ns 20.4 ns 719.8 ns
  • The claim is about construction by name, timeZoneId and equals. An offset or a field of a ZonedDateTime still takes the lock of Temporal's cache of zones, as on main.
  • The structure is the one of Records in aot/ir/AOTSharedAnswers.h: records that never move, an index of atomic slots, adds under a lock.
  • If the lock-free registry is not wanted, the locked one replaces the class and nothing else, at the cost in the table.

Considered: a patch to ICU in place of commit 2

Calendar::setWeekData asks for the minimized locale before it needs it, and that is what loads the likely-subtags data. First read in jsc, TZ=America/Los_Angeles, instructions / faults, with commit 1 in every row:

UCalendar, stock ICU (commit 1) 17,683,261 / 492
the same, calendar opened with "en_US" 17,669,091 / 490
UCalendar, patched ICU, calendar opened with "" as now 17,670,614 / 492
UCalendar, patched ICU, calendar opened with "en_US" 236,085 / 37
icu::TimeZone (commit 2) 106,119 / 25
  • The patch needs both halves: ICU changed, and a locale with a region at the three sites.
  • It changes no per-call cost. The two microbenchmarks above stay at the numbers of commit 1.
  • Seven build recipes in two repositories apply ICU's patches by hand (Dockerfile, Dockerfile.musl, Dockerfile.freebsd, Dockerfile.android, Dockerfile.windows, build-icu.ps1, and scripts/build/hardened-icu.sh in bun).
  • It keeps the fork's code as upstream has it, and uses no C++ API. If that is preferred, commit 1 lands alone and the patch replaces commit 2.
  • A patch of that kind is the way to the first Intl.DateTimeFormat, which commit 2 cannot reach. This hunk alone does not remove the load there: ICU's calendar of the default century is opened without a region (gregoimp.h).

TZ unset and /etc/localtime a regular file

ICU then finds the host's zone by comparing that file with the files under /usr/share/zoneinfo (443 here). JavaScriptCore asks once, and ICU asks again for its own default zone. On main both happen in the first read. Here the second one moves to the first toString() or Intl use. jsc, times in the process:

main commit 1 both
first getHours() 3.009 ms 1.766 ms 0.347 ms
first toString() 3.114 ms 1.849 ms 0.686 ms
getHours(), then toString() 3.021 + 0.112 ms 1.746 + 0.106 ms 0.333 + 0.339 ms
  • bun, first getHours(): 3.039 ms to 0.273 ms. node: 0.299 ms.
  • With /etc/localtime a symlink, which is what every other table here has: 2.583 + 0.100 ms, 1.320 + 0.092 ms and 0.104 + 0.171 ms.
  • To give ICU the zone that JavaScriptCore found would remove the second search. It is not in this PR: [JSC] The host time zone is not UTC when ICU has no name for it #890 changes the same function.

Same results

  • 802 values of TZ: the 638 names of ICU, 66 invalid or unusual values, 98 names in another case. For each: the offset at 86,000 instants from 1880 to 2100, 70,000 local times that include every skipped and repeated one of four years, both names in Date.prototype.toString(), and the default zone of Intl and Temporal.
  • Each value as the TZ of a new process, and each as a change inside one process ($vm.setHostTimeZone() in jsc, process.env.TZ = in bun). Each of these with the first Date read first, with Intl.DateTimeFormat() first, and with Intl.supportedValuesOf("timeZone") first.
  • 4,815 lines of output each, identical to main: jsc at commit 1, jsc at commit 2, jsc at commit 2 with the UCalendar arm forced, and bun.
  • JSTests with --quick: 35,334 runs, 10 failures, none about dates or zones. 7 fail on main every time in this container: BigInt tests that run out of memory, auxiliary-evacuation-with-concurrent-compiles, get-array-length-concurrently-change-mode. The other 3 are bigint-terminate-*, which wait for the watchdog. They fail under load on main too, and pass alone.
  • Commit 1 alone: built, its 7 tests pass. 8,314 runs of JSTests that a filter for time zones, Temporal, Intl and dates selects: 2 failures, both of the 7 above.
  • testaot all: 5,036 passed, 0 failed, 45 todo.
  • API/tests/TemporalCoreTest.cpp, which no lane builds, through a driver that calls testTemporalCore(): all tests pass, with each arm.
  • Debug build with ASAN: the 9 new JSTests pass, the thread test 40 times of 40.
  • bun with this WebKit, release: temporal.test.ts, temporal-global.test.ts, deep-equals-temporal.test.ts, cron.test.ts, cron-local-time.test.ts, cron-parse.test.ts, in-process-cron.test.ts, intl.test.ts, bun-jsc.test.ts, sql-timezone.test.js, cookie.test.ts, fake-timers.test.ts, v8-date-parser.test.js, test/aot/time-zone-at-start.test.ts, test-process-env-tz.js, test-datetime-change-notify.js.
  • bun with this WebKit, debug with ASAN, with the options of bun's test runner (detect_leaks=1, BUN_DESTRUCT_VM_ON_EXIT=1, test/leaksan.supp): the same files without the AOT and sqlite ones, no leak report. An earlier revision allocated the slots of the registry's index with new[]. With that put back, temporal.test.ts aborts with Direct leak of 128 byte(s) from TimeZoneRegistry::Index::create.

What each test catches

Each row is one change to the code, and the test that fails with it.

change fails
the UCalendar arm on Linux bun-time-zone-holder-loads-no-locale-data.js: ICU has loaded 9 data items after the first read, where it loads 3
getTimeZoneTransition does not search on past a change of rule bun-temporal-time-zone-transition-is-an-offset-change.js
findUTCOffset: a stretch that ends an hour late, starts 1 ms early, or leaves the DST offset out formatter-of-a-named-time-zone-is-laid-down-as-a-pattern.ir
an alias is remembered as no zone bun-time-zone-by-name-agrees-with-table.js
supportedValuesOf lists aliases the same, and bun-time-zone-first-use-lists-no-zones.js
a name of ICU that is no zone is not remembered bun-time-zone-first-use-lists-no-zones.js (questions to ICU)
the registry is not read before ICU is asked the same
what a canonical identifier gives is not kept the same
a primary identifier goes to the list of names the same, and complex/bun-host-time-zone-lists-no-zones.js
a new index leaves zones out the same
add() does not look for the identifier first the same, and the thread test
zones are added without the lock bun-time-zone-named-by-many-threads.js, in 56 runs of 60
  • The first row needs a shell that reads ICU's data as Bun packs it, which the Linux lanes build. The test says nothing in another shell.
  • One clause has no such test. isPrimaryTimeZoneIdentifier asks whether the canonical identifier of a name is its own canonical identifier, as ICU's canonical enumeration does. ICU 79.1 has no name for which the answer is no.

How a name is resolved

  • A primary identifier as ICU spells it: ucal_getCanonicalTimeZoneID gives the canonical identifier of the name. The code that the table runs for a canonical name (primaryTimeZoneIdentifierOfCanonicalICUTimeZone) has to give the name back.
  • Every other name goes to the names that ucal_openTimeZones lists. The table takes its aliases from that list, so US:Pacific, UTC<NUL>x and a CLDR alias that the zone data lacks cannot pass. ICU's own lookup of one name accepts the first two.
  • A name that is not on the list is no zone, and costs one lookup. This rests on one fact about ICU's data: every primary identifier is a name of the list. bun-time-zone-by-name-agrees-with-table.js fails when that is not so.
  • $vm.timeZoneTable(), $vm.timeZoneInTable() and $vm.timeZoneByName() are the hooks of that test. A release build of Bun has no $vm, so upstream's table is not linked into it: bun is 10,300 bytes of text smaller. jsc is 6,824 bytes larger.

Not in this change

Self-review

30 concerns were raised, and this is what changed for them:

  • The registry's index is one fastMalloc block. LeakSanitizer reported the new[] of its slots in bun.
  • A name that ICU lists and that is no zone is remembered. It asked ICU again on every call.
  • Intl.supportedValuesOf("timeZone") is made by the resolver. It built upstream's table, and the registry took the table over, so there were two sources of zones in production.
  • What ICU gives a canonical identifier is kept, so that no order of names costs more than main.
  • The change is two commits. Commit 1 was built and tested alone.
  • New tests: the ICU data item test, the transition test, the AOT walk test, the second phase of the thread test, and the counts of questions to ICU.
  • The numbers are of the final build, with the lock comparison in time, the ICU patch, a TZ change, and what is not fixed.

Not addressed: no lane runs the tests on macOS or Windows.

A TimeZoneID was an index into a table of every time zone identifier. The first name that a process
gave to a time zone built the table: two enumerations of ICU's zones and a primary identifier for
every name, about 21 million instructions. The host's zone is such a name, so the first local-time
read of a Date built the table.

Under USE(BUN_JSC_ADDITIONS) a TimeZoneID is now the order in which the process first named an
identifier, and UTC is always 0. TimeZoneRegistry (IntlObject.cpp) keeps the identifiers that the
process has named. ICU is asked about one name at a time, by the rules of the table:

- A primary identifier as ICU spells it. ICU's canonical identifier of the name has to be its own
  canonical identifier, which is how ICU chooses the names of its canonical enumeration. Then the
  code that the table runs for such a name has to give the name back. What that code gives a
  canonical identifier is kept, because an alias has the canonical identifier of its primary.
- Every other name is looked up in the names that ucal_openTimeZones lists, which is about
  1.9 million instructions, once. The table takes its aliases from that list, so a name that the
  list does not have is no zone. A name of the list that is no zone (PST, SystemV/EST5) is
  remembered as none.
- Intl.supportedValuesOf("timeZone") asks the same about every name of the list. Upstream's table
  stays for the tests, which hold the two against each other.

A thread reads the registry without a lock, as it read the table. A zone is complete before it can
be found and never changes, and an index that is replaced stays. With a WTF::Lock around a HashMap
in its place, new Temporal.ZonedDateTime(0n, name) takes 3,210 ns a call in each of 8 threads,
against 59 ns, and zoned.timeZoneId takes 16 ns in one thread, against 7 ns.

Linux x64, ICU 79.1, release build of jsc. Instructions of the first local-time read of a Date,
over the same script with getUTCHours():

    TZ                     before        after
    unset                  38,651,503    17,656,954
    America/Los_Angeles    38,667,174    17,673,463
    america/los_angeles    38,964,180    19,499,958
    Invalid/Zone           38,978,922    19,472,196

What is left opens a calendar for the zone. The next commit replaces the calendar.

First use of names, over a script that names no zone, without the JIT:

    Intl.supportedValuesOf("timeZone")               21,154,760    20,898,253
    one primary identifier                           21,125,646        87,139
    the 445 primary identifiers, one by one          22,415,614    14,644,941
    an alias                                         21,090,074     1,926,120
    all 638 names of ICU, one by one                 23,465,481    22,590,582
    200 primary identifiers, then supportedValuesOf  22,129,332    21,932,502

Per call: new Temporal.ZonedDateTime(0n, name) 1,608 to 1,204 instructions, with an alias 2,046 to
1,169, with "PST" (throws) 5,874 to 4,968, with a name that ICU does not list (throws) 5,907 to
5,060.

Tests:
- stress/bun-time-zone-by-name-agrees-with-table.js compares the answer by name with upstream's
  table for every identifier of the table, 25 other spellings of each and names that are no zones,
  and Intl.supportedValuesOf("timeZone") with the primaries of the table.
- stress/bun-time-zone-first-use-lists-no-zones.js says what each kind of name makes ICU list, and
  which names are answered without a question to ICU.
- stress/bun-time-zone-named-by-many-threads.js names zones in 8 threads at once, and for the first
  time in 7 threads while the eighth lists every zone. A fault there shows in some runs only.
- complex/bun-host-time-zone-*.js give the host's zone as TZ gives it: a primary identifier, another
  case, an alias in another case, a name that is no zone.
DateCache, Temporal's bridge to ICU and the date patterns of the AOT compiler each opened a
UCalendar to ask a time zone for its offsets, its transitions and its names. ICU's C API has no
time zone object. The ICU that Bun bundles opens no calendar without its likely-subtags data
(Calendar::setWeekData): about 17.6 million instructions and 470 page faults, once per process.

ICUTimeZone (runtime/ICUTimeZone.h) holds one zone for the three of them.

- Where Bun links the ICU that it bundles (Linux, Windows, FreeBSD, Android) it is an
  icu::TimeZone. Its queries are the calls that ucal.cpp makes on the zone of a calendar.
  ICUTimeZone.cpp is the only file that sees ICU's C++ headers, and it is in no unified source.
- On Darwin Bun links the system's ICU, of which only the C API is stable, and it is a UCalendar.
  Two calls on that calendar are gone, ucal_setGregorianChange and ucal_clear: they change the
  fields of a calendar, and no offset, transition or name of a zone. The calendar of the AOT
  compiler was UCAL_GREGORIAN and is UCAL_DEFAULT, as the other two were.

Linux x64, ICU 79.1, release build of jsc. Instructions and minor page faults of the first
local-time read of a Date, over the same script with getUTCHours():

    TZ                     before              after
    unset                  17,656,954 / 493     91,734 / 22
    UTC                    17,645,966 / 488     69,780 / 24
    America/Los_Angeles    17,673,463 / 490    106,231 / 23
    america/los_angeles    19,499,958 / 507  1,946,885 / 41

With the calendar arm forced on Linux the first read is 17,628,747 / 490 (TZ unset). That is the
cost of the bundled ICU. The ICU of macOS was not measured.

Per call: a Date read that misses the cache of offsets 2,928 to 2,130 instructions, a local time
to UTC 2,957 to 2,608, an offset of a named zone through Temporal 3,077 to 2,274.
JSTests/microbenchmarks/temporal-zoned-date-time-time-zone-cache.js 4,368.5 to 2,423.8 million
instructions, temporal-zoned-date-time-from-named-time-zone.js 388.5 to 280.1 million.

Tests:
- stress/bun-time-zone-holder-loads-no-locale-data.js. The shell counts the items of ICU's data
  that ICU loads (icuDataItemCount(), where the shell reads the data as Bun packs it). After the
  first local-time read, the name of the host's zone, and the offsets and transitions of a named
  zone, to maximize a locale still loads an item. With a calendar at one of these sites it loads
  none, and the test fails.
- stress/bun-temporal-time-zone-transition-is-an-offset-change.js. getTimeZoneTransition() passes
  over the transitions of ICU that change no offset, forward and backward.
- aot/tests/walk/builtin-calls/formatter-of-a-named-time-zone-is-laid-down-as-a-pattern.ir. The
  pattern of a formatter that names a zone is laid down only where the offsets and the stretches
  that findUTCOffset gives agree with what ICU formats.
@robobun

robobun commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. It waits for CI and for a maintainer's answer to the two choices under Background.

How the problem was reproduced (Linux x64, main at cbf8d97):

  • jsc runs new Date(1700000000000).getHours(), and the same script with getUTCHours(). The first one takes 38.7 million more user instructions and 520 more minor page faults (perf_event_open, median of 21 runs), for every value of TZ.
  • gdb counts, in that run: LikelySubtags::initLikelySubtags 1, TZEnumeration::create 2, ucal_open 1, ucal_getIanaTimeZoneID 611.
  • In bun, performance.now() around the same read: 2.5 ms. node v26.3.0: 0.05 ms.

With this PR: 0.1 million instructions and 22 faults in jsc, 0.02 ms in bun with TZ set. The output of 802 values of TZ is identical to main.

Not run here: macOS and Windows. The lanes of this PR compile both.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR and didn't find any bugs. Because it introduces a lock-free process-wide TimeZoneRegistry and the fork's first use of ICU's C++ API in paths under Source/JavaScriptCore (jsc-reviewers in CODEOWNERS), a human look would still be worthwhile, as the description itself asks for.

What was reviewed:

  • TimeZoneRegistry publication order (segment store, m_zoneCount release, index slot release) against the lock-free find()/zone() readers, index resizing with the kept-alive replaced index, and placeOf segment math.
  • The three calendar sites moved onto ICUTimeZone (JSDateMath.cpp, TimeZoneICUBridge.cpp, AOTIntlBuiltinOperations.cpp): the transition loop's Previous/Next search points and the dropped ucal_clear/ucal_setGregorianChange on the Darwin UCalendar path were checked — every query sets millis before reading and zone offsets do not depend on the Gregorian cutover.
  • Name resolution before and after ICU's name list exists (primary, alias, other-case, non-IANA) was traced for agreement with the table rules; the RangeError-consistency concern was ruled out because every primary identifier is on the ucal_openTimeZones list.
  • Not done in this run: no build, testaot, or JSTests execution — the new stress/complex tests and the macOS/Windows paths were only read.
Extended reasoning...

The change replaces JSC's eager all-zones time zone table with a per-name registry under USE(BUN_JSC_ADDITIONS), adds a new ICUTimeZone wrapper (icu::TimeZone on non-Darwin, UCalendar on Darwin), rewires DateCache, Temporal's TimeZoneICUBridge and the AOT Intl helper onto it, and adds nine JSTests plus a testaot IR test and $vm/jsc hooks. It touches no auth, injection or data-exposure surface. The bug hunt ran dry with no findings and the ruled-out candidates hold up on reading, but the PR is about 1,800 lines, hand-rolls a lock-free hash index and segmented arena read without a lock, and is the fork's first use of ICU's C++ API, which the author explicitly flags as needing a maintainer decision; the paths are also covered by CODEOWNERS. Those facts decided defer over approve.

@github-actions

Copy link
Copy Markdown

Preview build of 420e51a: autobuild-preview-pr-1086-420e51a3

@robobun

robobun commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up on the first Intl.DateTimeFormat, which the description lists under "Not fixed". I measured it and wrote an ICU patch for it. I do not open a pull request for the patch. The two reasons are at the end.

What loads the table on this head

  • The load is icu_79::LikelySubtags::initLikelySubtags: 22.5 million instructions and 435 page faults in a jsc without LTO.
  • Four places in ICU's i18n library ask the table for a locale that has a region and do not use the answer: Calendar::setWeekData (calendar.cpp:4103), the default-century calendar (gregoimp.h:374), GregorianCalendar::setGregorianChange (gregocal.cpp:323) and SimpleTimeZone::inDaylightTime (simpletz.cpp:728). The last two make a calendar in ICU's default locale. They ask when that locale has no region (LANG=de, an empty LANG) or has a script.
  • With the four changed, the first new Intl.DateTimeFormat() on this head goes from 43.8 to 21.4 million instructions and from 3.13 to 1.56 ms. Intl output is equal for 3,017 locale tags. ICU's intltest and cintltst pass.
  • On main without this PR, only a format with a timeZone option gains (66.6 to 44.1 million instructions). The root-locale calendar of DateCache loads the table first.

Why no pull request

The branch robobun/e7db8fcf/icu-calendar-likely-subtags has the patch, the recipe lines and a test that fails without any one of the four changes. It has no pull request, so it runs no CI. If oven-sh/bun#49369 does not land, it can become one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants