Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f6d1b6eb589dcf909f1770238f5a682260990f73
      
https://github.com/WebKit/WebKit/commit/f6d1b6eb589dcf909f1770238f5a682260990f73
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-04-24 (Fri, 24 Apr 2026)

  Changed paths:
    A JSTests/microbenchmarks/string-pad-end-consume.js
    A JSTests/microbenchmarks/string-pad-end-indexof.js
    A JSTests/stress/string-pad-flat-result.js
    M Source/JavaScriptCore/runtime/StringPrototype.cpp

  Log Message:
  -----------
  [JSC] Produce flat string from `padStart` / `padEnd` for short results
https://bugs.webkit.org/show_bug.cgi?id=312740

Reviewed by Yusuke Suzuki.

Currently padStart / padEnd always return a 2-fiber rope by concatenating
the filler and `this` via jsString(). When the result is consumed (e.g.
charCodeAt, indexOf, or as an element passed to Array#join), the rope must
be resolved, allocating yet another buffer.

This patch produces a flat string directly when the result length is
<= 1024, matching the existing threshold used by String.prototype.repeat.
The filler is written via doubling memcpy and `this` is copied into the
same buffer in one allocation. The 8 / 1024 thresholds are now shared
between repeat and padStart/padEnd as maxPatternLengthForFlatRepeat /
maxResultLengthForFlatRepeat.

                                TipOfTree                  Patched

string-pad-end-indexof       94.1830+-15.9586    ^     58.3430+-2.8945        ^ 
definitely 1.6143x faster
string-pad-end-consume       69.5300+-4.4738     ^     49.9553+-4.2149        ^ 
definitely 1.3918x faster

Tests: JSTests/microbenchmarks/string-pad-end-consume.js
       JSTests/microbenchmarks/string-pad-end-indexof.js
       JSTests/stress/string-pad-flat-result.js

* JSTests/microbenchmarks/string-pad-end-consume.js: Added.
(bench):
* JSTests/microbenchmarks/string-pad-end-indexof.js: Added.
(bench):
* JSTests/stress/string-pad-flat-result.js: Added.
(shouldBe):
(shouldBe.string_appeared_here.padStart):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::fillBufferWithPattern):
(JSC::createFillerString):
(JSC::createPaddedString):
(JSC::padString):
(JSC::JSC_DEFINE_HOST_FUNCTION):

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



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

Reply via email to