[webkit-changes] [WebKit/WebKit] 2340b0: [JSC] Add a fast path for String.prototype.replace...
Yijia Huang
noreply at github.com
Tue Oct 1 13:32:46 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2340b02da4545f77aa1c4f2be26aa84117ca2f1d
https://github.com/WebKit/WebKit/commit/2340b02da4545f77aa1c4f2be26aa84117ca2f1d
Author: Yijia Huang <yijia_huang at apple.com>
Date: 2024-10-01 (Tue, 01 Oct 2024)
Changed paths:
A JSTests/microbenchmarks/string-replace-one-char-long-string-string-string.js
A JSTests/microbenchmarks/string-replace-one-char-short-string-string-string.js
M Source/JavaScriptCore/dfg/DFGOperations.cpp
M Source/JavaScriptCore/runtime/JSString.h
M Source/JavaScriptCore/runtime/JSStringInlines.h
M Source/JavaScriptCore/runtime/Operations.h
M Source/JavaScriptCore/runtime/StringPrototype.cpp
M Source/JavaScriptCore/runtime/StringPrototypeInlines.h
Log Message:
-----------
[JSC] Add a fast path for String.prototype.replace one char with a simple string
https://bugs.webkit.org/show_bug.cgi?id=280429
rdar://136775172
Reviewed by Yusuke Suzuki.
Rope string consists of three fibers which can be either a rope string
or a regular string. To replace one character with a simple string in
a rope string. The current implementation constructs the entire string
by concatenating all fiber leaves first, which is costly. This patch
proposes a fast path for replacing one character, which finds the
matched fiber leaf first and then reconstructs with rope strings.
This approach can get rid of the costly overhead for resolving the
entire string.
Micro-benchmark Result with `--inner 20 --outer 20`:
before after
string-replace-one-char-long-string-string-string 2.0279+-0.0171 ^ 0.2663+-0.0066 ^ definitely 7.6157x faster
string-replace-one-char-short-string-string-string 1.0679+-0.0078 ^ 0.8676+-0.0085 ^ definitely 1.2309x faster
* JSTests/microbenchmarks/string-replace-one-char.js: Added.
(test):
* Source/JavaScriptCore/runtime/JSString.cpp:
(JSC::JSString::replaceOneCharImpl):
(JSC::JSString::replaceOneChar):
* Source/JavaScriptCore/runtime/JSString.h:
* Source/JavaScriptCore/runtime/RegExp.h:
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::tryReplaceOneChar):
(JSC::replaceUsingRegExpSearch):
Canonical link: https://commits.webkit.org/284507@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list