Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 33a5272cf9acb5e290cb58b1ec6b5a9a1ef1ee70
      
https://github.com/WebKit/WebKit/commit/33a5272cf9acb5e290cb58b1ec6b5a9a1ef1ee70
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-04 (Tue, 04 Aug 2026)

  Changed paths:
    A JSTests/microbenchmarks/locale-compare-with-locales.js
    A JSTests/stress/string-locale-compare-locales-cache.js
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
    M Source/JavaScriptCore/runtime/JSGlobalObject.h
    M Source/JavaScriptCore/runtime/StringPrototype.cpp

  Log Message:
  -----------
  [JSC] Cache the collator for `String#localeCompare` with a string locale
https://bugs.webkit.org/show_bug.cgi?id=320962

Reviewed by Yusuke Suzuki.

`String#localeCompare(that, locale)` created a fresh IntlCollator on
every call whenever `locales` was not undefined, running full option
probing, resolveLocale and ucol_open per comparison. This makes the
common sort comparator pattern
`items.sort((a, b) => a.name.localeCompare(b.name, "en"))` very slow.

This patch adds a single-entry per-JSGlobalObject cache keyed by the
locale string, used when `locales` is a string and `options` is
undefined. In that case examining the arguments has no observable side
effects, so reusing the collator is not observable (V8 caches the
collator under the same condition).

                                      baseline                  patched

locale-compare-with-locales      111.1431+-2.0657     ^      2.0815+-0.0727     
   ^ definitely 53.3946x faster
locale-compare                     0.9404+-0.0560            0.9292+-0.0475     
     might be 1.0120x faster

Tests: JSTests/microbenchmarks/locale-compare-with-locales.js
       JSTests/stress/string-locale-compare-locales-cache.js

* JSTests/microbenchmarks/locale-compare-with-locales.js: Added.
* JSTests/stress/string-locale-compare-locales-cache.js: Added.
(shouldBe):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::visitChildrenImpl):
(JSC::JSGlobalObject::cachedLocaleCompareCollator):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Canonical link: https://commits.webkit.org/318542@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to