Consider rewriting some self-hosted RegExp builtins in C++
Categories
(Core :: JavaScript Engine, task, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox115 | --- | fixed |
People
(Reporter: jandem, Assigned: jandem)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3])
Attachments
(7 files)
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details |
Self-hosting probably makes sense for some of the functions that (can) take a callback argument like replace
, but for exec
and test
we can likely get rid of some overhead by implementing in C++ and optimizing the builtin in the JITs.
The main difficulty is updating the .lastIndex
value for global/sticky regular expressions, but that should be doable with CacheIR now.
Assignee | ||
Updated•1 year ago
|
Updated•1 year ago
|
Assignee | ||
Comment 1•1 year ago
|
||
I started prototyping this for RegExpBuiltinExec
, because that's near the bottom of the call stack. Implementing it in C++ is nice so far, it lets us get rid of some layers of abstraction.
Assignee | ||
Comment 2•1 year ago
|
||
I have some WIP patches to port these to C++:
RegExpBuiltinExec
RegExpExec
RegExp_prototype_Exec
Next step is to see how this affects Speedometer.
These can mostly share the same CacheIR code for the fast path. After this there are other self-hosted functions one layer up that we might be able to port to C++ too (RegExpTest
, maybe RegExpMatch
).
Assignee | ||
Comment 3•1 year ago
|
||
(In reply to Jan de Mooij [:jandem] from comment #2)
RegExp_prototype_Exec
This one is a bit of a problem because it's sometimes polymorphic. Octane-regexp calls it with a string-or-undefined argument, so my patches regressed our score on that test a lot, and a Speedometer 3 test (I think React-Stockcharts) calls it with an object argument (hard to support because side-effects).
RegExp_prototype_Exec
is a small wrapper around RegExpBuiltinExec
so let's start with just RegExpBuiltinExec
and RegExpExec
. This improves our Octane-regexp score by a few hundred points and should be a small win on Speedometer.
Assignee | ||
Comment 4•1 year ago
|
||
We want to reuse this in the next patch.
Also add an isInitialShape
fast path to it, which turned out to be missing a check
for is-still-writable.
Assignee | ||
Comment 5•1 year ago
|
||
This is faster than the self-hosted implementation, especially with the JIT
optimizations added in later patches.
IC and Ion code will call the RegExpBuiltinExecMatchRaw
and RegExpBuiltinExecTestRaw
functions directly.
Depends on D177504
Assignee | ||
Comment 6•1 year ago
|
||
Usually .exec
will be the original RegExp.prototype.exec
function, and in that case
we can call RegExpBuiltinExec
.
Depends on D177505
Assignee | ||
Comment 7•1 year ago
|
||
Depends on D177506
Assignee | ||
Comment 8•1 year ago
|
||
These are very similar to RegExpMatcher
and RegExpTester
, except that we have some
additional code for reading/writing lastIndex
.
The next patch will remove RegExpTester
.
Depends on D177507
Assignee | ||
Comment 9•1 year ago
|
||
Depends on D177508
Assignee | ||
Comment 10•1 year ago
|
||
Speedometer 3 comparison:
Sorting sub-tests by confidence shows a number of high-confidence 2-4% improvements.
Comment 11•1 year ago
|
||
Very nice! But huh, Backbone got slower in some places! I was expecting Backbone to benefit the most.
Assignee | ||
Comment 12•1 year ago
|
||
Callers typically pass a constant true/false so we can get rid of a CacheIR guard in this case.
Depends on D177509
Comment 13•1 year ago
|
||
Comment 14•1 year ago
|
||
Backed out for causing dt failure on browser_script_command_execute_basic.js.
[task 2023-05-11T16:29:59.036Z] 16:29:59 INFO - TEST-PASS | devtools/shared/commands/script/tests/browser_script_command_execute_basic.js | property 'input'undefined -
[task 2023-05-11T16:29:59.038Z] 16:29:59 INFO - checking object for property 'result'undefined
[task 2023-05-11T16:29:59.039Z] 16:29:59 INFO - TEST-PASS | devtools/shared/commands/script/tests/browser_script_command_execute_basic.js | property 'type'undefined -
[task 2023-05-11T16:29:59.040Z] 16:29:59 INFO - Buffered messages finished
[task 2023-05-11T16:29:59.045Z] 16:29:59 INFO - TEST-UNEXPECTED-FAIL | devtools/shared/commands/script/tests/browser_script_command_execute_basic.js | no eval exception -
[task 2023-05-11T16:29:59.046Z] 16:29:59 INFO - Stack trace:
[task 2023-05-11T16:29:59.046Z] 16:29:59 INFO - chrome://mochikit/content/browser-test.js:test_ok:1584
[task 2023-05-11T16:29:59.047Z] 16:29:59 INFO - chrome://mochitests/content/browser/devtools/shared/commands/script/tests/browser_script_command_execute_basic.js:doEagerEvalWithSideEffectMonkeyPatched:603
[task 2023-05-11T16:29:59.048Z] 16:29:59 INFO - chrome://mochitests/content/browser/devtools/shared/commands/script/tests/browser_script_command_execute_basic.js:null:89
[task 2023-05-11T16:29:59.049Z] 16:29:59 INFO - chrome://mochikit/content/browser-test.js:handleTask:1133
[task 2023-05-11T16:29:59.050Z] 16:29:59 INFO - chrome://mochikit/content/browser-test.js:_runTaskBasedTest:1205
[task 2023-05-11T16:29:59.051Z] 16:29:59 INFO - chrome://mochikit/content/browser-test.js:Tester_execTest:1347
[task 2023-05-11T16:29:59.052Z] 16:29:59 INFO - chrome://mochikit/content/browser-test.js:nextTest/<:1122
[task 2023-05-11T16:29:59.052Z] 16:29:59 INFO - chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:SimpleTest.waitForFocus/<:1056
[task 2023-05-11T16:29:59.056Z] 16:29:59 INFO - TEST-PASS | devtools/shared/commands/script/tests/browser_script_command_execute_basic.js | no helper result -
Assignee | ||
Comment 15•1 year ago
|
||
(In reply to Iulian Moraru from comment #14)
Backed out for causing dt failure on browser_script_command_execute_basic.js.
This is a devtools eager evaluation failure. The call to (overridden) exec
functions in RegExpExec
needs to be marked as CallReason::CallContent
.
Comment 16•1 year ago
|
||
Comment 17•1 year ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/181d38478102
https://hg.mozilla.org/mozilla-central/rev/1c9a6dc02923
https://hg.mozilla.org/mozilla-central/rev/bf65109b6c41
https://hg.mozilla.org/mozilla-central/rev/68dd64a6dbe8
https://hg.mozilla.org/mozilla-central/rev/9e2a3f04e0ac
https://hg.mozilla.org/mozilla-central/rev/05b3296dcc61
https://hg.mozilla.org/mozilla-central/rev/5ac14c27f807
Description
•