Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JSC] Optimize String.replace with String / String case more in DFG /…
… FTL https://bugs.webkit.org/show_bug.cgi?id=244750 Reviewed by Saam Barati. While DFG / FTL has optimization for String#replace(RegExp, String), we didn't have optimization for String#replace(String, String). This patch adds that optimization since Speedometer2.1 includes String#replace(String, String). 1. We simply add StringReplace with 3 StringUse specialization in DFG. And we invoke very simple operation function for the fast processing. To achieve that, we need to have String.prototype.@@replace and Object.prototype.@@replace watchpoints to ensure that these properties are not defined. 2. We add String#replace(String, String) strength reduction. So if everything is constant, we will convert it into constant LazyJSString node. 3. To clean up further, we also introduce watchpoints for RegExp primordial properties. We would like to move to the new implementation leveraging this for String#replace(RegExp, String) case in the future too to avoid inserting tryGetById in Fixup phase. Microbenchmark shows 2x improvement. On Intel machine, Speedometer2.1 gets 0.45% faster. And on AppleSilicon machine, 0.26% faster. In particular Vanilla-ES2015-Babel-Webpack-TodoMVC gets 2% better, Vanilla-ES2015-TodoMVC gets 1.93% better, and VanillaJS-TodoMVC gets 2.94% better. ToT Patched string-replace-string 707.7036+-2.0437 ^ 349.5370+-1.3370 ^ definitely 2.0247x faster * JSTests/microbenchmarks/string-replace-string.js: Added. (test): * Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * Source/JavaScriptCore/dfg/DFGClobberize.h: (JSC::DFG::clobberize): * Source/JavaScriptCore/dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * Source/JavaScriptCore/dfg/DFGGraph.h: * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/dfg/DFGOperations.h: * Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp: * Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp: (JSC::DFG::StrengthReductionPhase::handleNode): * Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq): * Source/JavaScriptCore/runtime/JSGlobalObject.cpp: (JSC::setupAdaptiveWatchpoint): (JSC::JSGlobalObject::init): * Source/JavaScriptCore/runtime/JSGlobalObject.h: (JSC::JSGlobalObject::stringSymbolReplaceWatchpointSet): (JSC::JSGlobalObject::regExpPrimordialPropertiesWatchpointSet): Canonical link: https://commits.webkit.org/254156@main
- Loading branch information
1 parent
647e67b
commit 965272b76dc3d55f84cb5702ab51ea62cc122e50
Showing
18 changed files
with
312 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function test(a, b, c) | ||
{ | ||
return a.replace(b, c); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e7; ++i) | ||
test("Hello World", "World", "Hi"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function test(string) { | ||
return string.replace("Hello", "World"); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test("Hello"), "World"); | ||
|
||
Object.prototype[Symbol.replace] = function () { return "Changed"; }; | ||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test("Hello"), "Changed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function test(string) { | ||
return string.replace(/Hello/, "World"); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e5; ++i) | ||
shouldBe(test("Hello"), "World"); | ||
|
||
RegExp.prototype[Symbol.replace] = function () { return "Changed"; }; | ||
for (var i = 0; i < 1e5; ++i) | ||
shouldBe(test("Hello"), "Changed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function test(string) { | ||
return string.replace("Hello", "World"); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test("Hello"), "World"); | ||
|
||
String.prototype[Symbol.replace] = function () { return "Changed"; }; | ||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test("Hello"), "Changed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function test() { | ||
return "Hello".replace("Hey", "World"); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test(), `Hello`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
function test() { | ||
return "Hello".replace("Hello", "World"); | ||
} | ||
noInline(test); | ||
|
||
for (var i = 0; i < 1e6; ++i) | ||
shouldBe(test(), `World`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.