Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3130bd507b02a77372bf2365ddf0164e546c6605
      
https://github.com/WebKit/WebKit/commit/3130bd507b02a77372bf2365ddf0164e546c6605
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-07-15 (Wed, 15 Jul 2026)

  Changed paths:
    A JSTests/microbenchmarks/string-replace-regexp-global-single-match.js
    A 
JSTests/microbenchmarks/string-replace-regexp-global-thousands-separator.js
    M Source/JavaScriptCore/runtime/JSString.h
    M Source/JavaScriptCore/runtime/OperationsInlines.h
    M Source/JavaScriptCore/runtime/StringPrototype.cpp
    M Source/JavaScriptCore/runtime/StringPrototypeInlines.h

  Log Message:
  -----------
  [JSC] Use the generic path in `jsSpliceSubstringsWithSeparator(s)` for short 
two-range results
https://bugs.webkit.org/show_bug.cgi?id=319023

Reviewed by Yusuke Suzuki.

For a global RegExp replace with a single match (rangeCount == 2, 
separatorCount == 1),
we create two substring StringImpls and concatenate them with jsString(). But 
when the
result is short, jsString() flattens it via tryMakeString() anyway, so this 
costs three
allocations and a double copy — strictly slower than the generic 
single-allocation path
below. This hits the common thousands-separator idiom
`String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ",")` for 4-6 digit numbers.

Take the special case only when jsString() would actually make a rope. The 
threshold is
extracted into shouldMakeRope() in JSString.h and shared with the jsString() 
overloads.

                                                   Baseline                  
Patched

string-replace-generic                         19.7240+-0.6320     ^     
14.7327+-0.3753        ^ definitely 1.3388x faster
string-replace-regexp-global-thousands-separator
                                              153.5817+-1.6965     ^    
120.7386+-1.0667        ^ definitely 1.2720x faster
string-replace-regexp-global-single-match
                                              152.1385+-0.4575     ^    
102.3380+-0.7269        ^ definitely 1.4866x faster

Tests: JSTests/microbenchmarks/string-replace-regexp-global-single-match.js
       
JSTests/microbenchmarks/string-replace-regexp-global-thousands-separator.js

* JSTests/microbenchmarks/string-replace-regexp-global-single-match.js: Added.
(test):
* JSTests/microbenchmarks/string-replace-regexp-global-thousands-separator.js: 
Added.
(test):
* Source/JavaScriptCore/runtime/JSString.h:
(JSC::shouldMakeRope):
* Source/JavaScriptCore/runtime/OperationsInlines.h:
(JSC::jsString):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::jsSpliceSubstringsWithSeparators):
(JSC::jsSpliceSubstringsWithSeparator):

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



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

Reply via email to