Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2b8c08245ca45124187a717bd6b26c4604f8b961
      
https://github.com/WebKit/WebKit/commit/2b8c08245ca45124187a717bd6b26c4604f8b961
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-06-18 (Thu, 18 Jun 2026)

  Changed paths:
    A JSTests/microbenchmarks/temporal-instant-to-locale-string.js
    A JSTests/microbenchmarks/temporal-plain-date-time-to-locale-string.js
    A JSTests/microbenchmarks/temporal-plain-date-to-locale-string.js
    A JSTests/microbenchmarks/temporal-plain-time-to-locale-string.js
    A JSTests/stress/temporal-tolocalestring-default-formatter.js
    M Source/JavaScriptCore/runtime/TemporalInstantPrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainDatePrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainMonthDayPrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainTimePrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainYearMonthPrototype.cpp

  Log Message:
  -----------
  [JSC][Temporal] `toLocaleString` should reuse the per-globalObject default 
`IntlDateTimeFormat` when locales/options are undefined
https://bugs.webkit.org/show_bug.cgi?id=315974

Reviewed by Yusuke Suzuki.

All six Temporal toLocaleString implementations created and initialized a fresh
IntlDateTimeFormat on every call, even in the most common case where both 
locales
and options are undefined. initializeDateTimeFormat is the most expensive Intl
constructor (~100us per call), and because the formatter was discarded after 
each
call, its internal per-TemporalFieldKind formatter cache 
(m_temporalFormatterCache)
was rebuilt every time as well.

Follow the same approach as Date.prototype.toLocaleString / toLocaleDateString /
toLocaleTimeString: when both locales and options are undefined, reuse the
per-globalObject default formatters. The (RequiredComponent, Defaults) pairs 
used
by each Temporal type match the existing defaults exactly, so no new 
globalObject
members are needed:

  - PlainDate, PlainMonthDay, PlainYearMonth -> defaultDateFormat() (Date, Date)
  - PlainTime -> defaultTimeFormat() (Time, Time)
  - PlainDateTime, Instant -> defaultDateTimeFormat() (Any, All)

This is unobservable: with undefined arguments, initializeDateTimeFormat runs no
user code, so the resulting configuration is deterministic. Sharing is also safe
because the legacy Date path formats through m_dateFormat while the Temporal 
path
formats through m_temporalFormatterCache, which are disjoint. As a bonus, the
Temporal formatter cache now survives across calls.

    temporal-plain-date-to-locale-string           87.4065+-0.6976     ^      
0.6863+-0.0602        ^ definitely 127.3515x faster
    temporal-plain-time-to-locale-string           87.8948+-1.6492     ^      
0.7042+-0.0537        ^ definitely 124.8110x faster
    temporal-plain-date-time-to-locale-string      95.9008+-0.7969     ^      
0.9443+-0.0996        ^ definitely 101.5602x faster
    temporal-instant-to-locale-string              99.6770+-1.3693     ^      
1.0900+-0.0762        ^ definitely 91.4445x faster

date-to-locale-string, date-to-locale-date-string, and 
date-to-locale-time-string
remain neutral.

Tests: JSTests/microbenchmarks/temporal-instant-to-locale-string.js
       JSTests/microbenchmarks/temporal-plain-date-time-to-locale-string.js
       JSTests/microbenchmarks/temporal-plain-date-to-locale-string.js
       JSTests/microbenchmarks/temporal-plain-time-to-locale-string.js
       JSTests/stress/temporal-tolocalestring-default-formatter.js

* JSTests/microbenchmarks/temporal-instant-to-locale-string.js: Added.
* JSTests/microbenchmarks/temporal-plain-date-time-to-locale-string.js: Added.
* JSTests/microbenchmarks/temporal-plain-date-to-locale-string.js: Added.
* JSTests/microbenchmarks/temporal-plain-time-to-locale-string.js: Added.
* JSTests/stress/temporal-tolocalestring-default-formatter.js: Added.
(shouldBe):
(const.object.of.formattable.object.toLocaleString):
(i.formattable.forEach):
* Source/JavaScriptCore/runtime/TemporalInstantPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalPlainDatePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalPlainMonthDayPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalPlainTimePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/TemporalPlainYearMonthPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

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



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

Reply via email to