Inline Array#forEach, Array#map etc.
Categories
(Core :: JavaScript Engine: JIT, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox89 | --- | fixed |
People
(Reporter: evilpie, Assigned: iain)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3])
Attachments
(1 file)
With bug 1666009 we can mark these array functions taking a callback as "LargeInlinableFunction". However we still can't inline them afterwards.
The problem seems to be the line:
var T = arguments.length > 1 ? arguments[1] : void 0;
In particular the arguments[1]
access marks the script as uninlineable: https://searchfox.org/mozilla-central/source/js/src/jit/IonAnalysis.cpp#3800
As far as I know we use arguments[1]
instead of having a second thisArg
parameter because otherwise function.length
would be 2. I don't really know what we should be doing here.
Updated•4 years ago
|
Assignee | ||
Comment 1•4 years ago
|
||
Bug 1688033 is adding support for inlining arguments[1]
. (It's currently behind the --scalar-replace-arguments
flag, but it should land fairly soon.) If I mark ArrayForEach
as inlinable in my local build, the following microbenchmark goes from ~18s to ~7s:
function foo(arr) {
var sum = 0;
arr.forEach(x => sum += x);
return sum;
}
function bar(arr) {
var sum = 0;
arr.forEach(x => sum += x);
return sum;
}
with ({}) {}
var input = [];
for (var i = 0; i < 100; i++) {
input.push(i);
}
for (var i = 0; i < 10000000; i++) {
assertEq(foo(input), 4950);
assertEq(bar(input), 4950);
}
(There are two different functions calling forEach
because otherwise we can inline the lambda function into the self-hosted code, which is not realistic outside of microbenchmarks.)
At the very least we should mark Array#forEach
, Array#map
, Array#some
, and Array#every
as inlinable. Not sure if filter/reduce/find are too big, or if we should inline those too.
Assignee | ||
Comment 2•4 years ago
|
||
This was ~3x faster in a microbenchmark for forEach
, every
, and some
, and ~2x faster for map
.
Updated•4 years ago
|
Comment 4•4 years ago
|
||
bugherder |
Updated•2 years ago
|
Updated•2 years ago
|
Description
•