Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 81a11702ef82c7a084d1a009dfa010b68e1e2981
      
https://github.com/WebKit/WebKit/commit/81a11702ef82c7a084d1a009dfa010b68e1e2981
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-06 (Thu, 06 Aug 2026)

  Changed paths:
    A JSTests/microbenchmarks/string-replace-regexp-trim-end.js
    A JSTests/microbenchmarks/string-replace-regexp-trim-start.js
    A JSTests/stress/trim-regexp-dfg.js
    M Source/JavaScriptCore/runtime/StringPrototype.cpp
    M Source/JavaScriptCore/runtime/StringPrototypeInlines.h

  Log Message:
  -----------
  [JSC] RegExp trim fast path in `String#replace` is skipped once the caller 
tiers up to DFG/FTL
https://bugs.webkit.org/show_bug.cgi?id=321161

Reviewed by Yusuke Suzuki.

291345@main added tryTrimSpaces() to replaceUsingRegExpSearch() so that
`str.replace(/^\s+/, "")` and `str.replace(/\s+$/, "")` avoid running the 
RegExp.
293816@main then made operationStringProtoFuncReplaceRegExpEmptyStr, which 
DFG/FTL
use for a constant empty replacement, call 
replaceOneWithStringUsingRegExpSearch()
directly, so the fast path has only been reachable from LLInt/Baseline since.

This patch moves the tryTrimSpaces() call into 
replaceOneWithStringUsingRegExpSearch(),
which both the runtime and the DFG operation go through, and removes the 
now-redundant
switch from replaceUsingRegExpSearch().

                                              Baseline                  Patched

string-replace-regexp-trim-end            75.2372+-0.4670     ^     
14.5417+-0.2654        ^ definitely 5.1739x faster
string-replace-regexp-trim-start          61.0601+-0.8583     ^     
13.5378+-0.3125        ^ definitely 4.5103x faster

Tests: JSTests/microbenchmarks/string-replace-regexp-trim-end.js
       JSTests/microbenchmarks/string-replace-regexp-trim-start.js
       JSTests/stress/trim-regexp-dfg.js

* JSTests/microbenchmarks/string-replace-regexp-trim-end.js: Added.
(test):
* JSTests/microbenchmarks/string-replace-regexp-trim-start.js: Added.
(test):
* JSTests/stress/trim-regexp-dfg.js: Added.
(shouldBe):
(testStart):
(testEnd):
(testOther):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::replaceOneWithStringUsingRegExpSearch):

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



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

Reply via email to