Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 733b18f696db58c67250673de025e075533a7fb5
https://github.com/WebKit/WebKit/commit/733b18f696db58c67250673de025e075533a7fb5
Author: Sosuke Suzuki <[email protected]>
Date: 2026-10-14 (Wed, 14 Oct 2026)
Changed paths:
A JSTests/microbenchmarks/number-to-locale-string-with-locales.js
A JSTests/stress/number-to-locale-string-locales-cache-language-change.js
A JSTests/stress/number-to-locale-string-locales-cache.js
M JSTests/stress/string-locale-compare-locales-cache-language-change.js
M Source/JavaScriptCore/runtime/BigIntPrototype.cpp
M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
M Source/JavaScriptCore/runtime/JSGlobalObject.h
M Source/JavaScriptCore/runtime/NumberPrototype.cpp
Log Message:
-----------
[JSC] `Number#toLocaleString` and `BigInt#toLocaleString` should reuse
`IntlNumberFormat` when only a locale string is given
https://bugs.webkit.org/show_bug.cgi?id=327503
Reviewed by Yusuke Suzuki.
`n.toLocaleString("en-US")` created an IntlNumberFormat on every call, and
a new ICU number formatter is slow for its first few uses. This patch caches
one IntlNumberFormat per JSGlobalObject, keyed by the locale string, in the
same way as the collator cache of String#localeCompare.
The cache is used only when locales is a string and options is undefined,
where creating the formatter runs no user code.
This patch also makes this cache and the collator cache miss while a
language change is pending, so that a change in the middle of a VM entry
is not ignored until the next entry.
Tests: JSTests/microbenchmarks/number-to-locale-string-with-locales.js
JSTests/stress/number-to-locale-string-locales-cache-language-change.js
JSTests/stress/number-to-locale-string-locales-cache.js
* JSTests/microbenchmarks/number-to-locale-string-with-locales.js: Added.
(test):
* JSTests/stress/number-to-locale-string-locales-cache-language-change.js:
Added.
(shouldBe):
(setTimeout):
* JSTests/stress/number-to-locale-string-locales-cache.js: Added.
(shouldBe):
(Intl.NumberFormat):
* JSTests/stress/string-locale-compare-locales-cache-language-change.js:
(setTimeout):
* Source/JavaScriptCore/runtime/BigIntPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::visitChildrenImpl):
(JSC::JSGlobalObject::cachedLocaleCompareCollator):
(JSC::JSGlobalObject::cachedToLocaleStringNumberFormat):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
* Source/JavaScriptCore/runtime/NumberPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
Canonical link: https://commits.webkit.org/323796@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications