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

  Changed paths:
    A JSTests/microbenchmarks/string-replace-string-substitution.js
    M Source/JavaScriptCore/runtime/IntlObject.cpp
    M Source/JavaScriptCore/runtime/IntlPluralRules.cpp
    M Source/JavaScriptCore/runtime/StringPrototypeInlines.h

  Log Message:
  -----------
  [JSC] Avoid intermediate `StringImpl` allocation when feeding `StringBuilder` 
into `makeString`
https://bugs.webkit.org/show_bug.cgi?id=317556

Reviewed by Yusuke Suzuki.

When a StringBuilder is passed to tryMakeString/makeString via toString(),
toString() shrinks the buffer and reifies a fresh StringImpl, which the
caller immediately copies from and discards. Passing StringView { builder }
lets the caller read directly from the builder's internal buffer.

Apply this in three places:

- tryMakeReplacedString (String.prototype.replace with a string search and
  a `$` substitution in the replacement). This matches what the RegExp path
  already does in replaceOneWithStringUsingRegExpSearch.
- resolveLocale, when stitching the supported -u- extension back into the
  found locale.
- IntlPluralRules::initializePluralRules, where the skeleton builder was
  reified only to be viewed as a StringView.

The Intl changes are allocation-only cleanups; ICU formatter construction
dominates those paths and the difference is below microbenchmark noise.

                                          Baseline               Fix

string-replace-string-substitution   67.4923+-0.7067  ^  57.4668+-0.5274  ^ 
definitely 1.1745x faster

Test: JSTests/microbenchmarks/string-replace-string-substitution.js

* JSTests/microbenchmarks/string-replace-string-substitution.js: Added.
(test):
* Source/JavaScriptCore/runtime/IntlObject.cpp:
(JSC::resolveLocale):
* Source/JavaScriptCore/runtime/IntlPluralRules.cpp:
(JSC::IntlPluralRules::initializePluralRules):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::tryMakeReplacedString):

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



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

Reply via email to