Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7e34b01578285a43c611c02e73395f885befdb39
      
https://github.com/WebKit/WebKit/commit/7e34b01578285a43c611c02e73395f885befdb39
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-05-28 (Thu, 28 May 2026)

  Changed paths:
    M Source/JavaScriptCore/runtime/IntlDurationFormat.cpp
    M Source/JavaScriptCore/runtime/IntlDurationFormat.h

  Log Message:
  -----------
  [JSC] Cache per-unit number formatters in `Intl.DurationFormat`
https://bugs.webkit.org/show_bug.cgi?id=315625

Reviewed by Yusuke Suzuki.

Intl.DurationFormat.prototype.format and formatToParts open a UNumberFormatter
(unumf_openForSkeletonAndLocale) for every displayed unit on every call, even
though, for a given DurationFormat, a unit's number skeleton is fixed by the
resolved options. This makes formatting a duration with several units
needlessly expensive.

Cache one formatter per unit on the instance, created lazily on first use and
held in a FixedVector. The formatters are sized by the resolved options, so they
can be reused across calls. The number of cached formatters does not depend on
the sign of the input: instead of building a separate sign-never skeleton
variant for trailing units, the trailing units are formatted with the absolute
value, which is observably equivalent and lets a single formatter per unit serve
both the leading (signed) and trailing (unsigned) positions. The estimated
native memory of each cached formatter is reported to the GC.

                                             TipOfTree                  Patched

intl-constructor-durationformat            8.4315+-0.5931            
8.1893+-0.5599          might be 1.0296x faster
intl-durationformat-format              1124.6364+-24.4749    ^     
42.4191+-0.6271        ^ definitely 26.5125x faster

* Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:
(JSC::IntlDurationFormat::visitChildrenImpl):
(JSC::collectElements):
(JSC::IntlDurationFormat::createNumberFormatterIfNecessary const):
* Source/JavaScriptCore/runtime/IntlDurationFormat.h:

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



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

Reply via email to