Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 99cab5c03916729d11da4f7af39d99192e32936a
https://github.com/WebKit/WebKit/commit/99cab5c03916729d11da4f7af39d99192e32936a
Author: Sosuke Suzuki <[email protected]>
Date: 2026-05-26 (Tue, 26 May 2026)
Changed paths:
M Source/JavaScriptCore/runtime/IntlCache.cpp
M Source/JavaScriptCore/runtime/IntlCache.h
M Source/JavaScriptCore/runtime/IntlObject.cpp
Log Message:
-----------
[JSC] Cache language tag canonicalization results in `IntlCache`
https://bugs.webkit.org/show_bug.cgi?id=315495
Reviewed by Justin Michaud.
CanonicalizeUnicodeLocaleId currently calls into ICU three times per requested
locale (uloc_forLanguageTag, uloc_canonicalize / ualoc_canonicalForm, and
uloc_toLanguageTag), which costs roughly 640ns per tag. Since every Intl
constructor, Intl.getCanonicalLocales, and supportedLocalesOf goes through
CanonicalizeLocaleList, this dominates the construction cost of cheap Intl
objects: profiling shows it accounts for about 37% of `new
Intl.NumberFormat("en-US")`.
Real-world code keeps passing the same handful of tags, so the work is highly
repetitive.
This patch adds a small per-VM memoization cache to IntlCache which maps an
input language tag to its canonicalized form. The cache is consulted from
canonicalizeLocaleList and defaultLocale. The first lookup for a tag still goes
through ICU, so cached results are always identical to what ICU would produce;
ICU data does not change during the lifetime of a process and canonicalization
does not depend on the default locale. The cache is bounded to 64 entries with
a 100-character key limit and is cleared when full, so the worst-case footprint
is a few KB per VM. Tags that are empty, non-ASCII, overly long, or fail
canonicalization are not cached and take the existing path.
TipOfTree Patched
intl-constructor-relativetimeformat 54.0186+-3.7287 ^
47.1160+-0.4646 ^ definitely 1.1465x faster
intl-constructor-datetimeformat 134.8669+-3.8817
126.5803+-4.8759 might be 1.0655x faster
intl-constructor-durationformat 8.9282+-1.2051 ^
3.6653+-0.3256 ^ definitely 2.4359x faster
intl-constructor-numberformat 20.4467+-0.4620 ^
13.7747+-0.1421 ^ definitely 1.4844x faster
intl-constructor-collator 13.9827+-1.3982 ^
7.0707+-0.1931 ^ definitely 1.9776x faster
* Source/JavaScriptCore/runtime/IntlCache.cpp:
(JSC::IntlCache::canonicalizeUnicodeLocaleID):
* Source/JavaScriptCore/runtime/IntlCache.h:
* Source/JavaScriptCore/runtime/IntlObject.cpp:
(JSC::canonicalizeLocaleList):
(JSC::defaultLocale):
Canonical link: https://commits.webkit.org/313929@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications