Remove hole check from LoadElementV
Categories
(Core :: JavaScript Engine: JIT, enhancement, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox142 | --- | fixed |
People
(Reporter: iain, Assigned: iain)
References
(Blocks 1 open bug)
Details
(Whiteboard: [js-perf-next])
Attachments
(3 files)
We use LLoadElementV to load a value from an array in Ion. When we do, we unconditionally generate a branchTestMagic to ensure that the value loaded is not the magic hole value. When we are looping over a large array, the cost of this check can add up. For example, on this microbenchmark, I get a 25% performance improvement by commenting out the hole check:
function foo(arr, i) {
return arr[i];
}
function bar() {
let result = 0;
for (var i = 0; i < arr.length; i++) {
result += foo(arr, i);
}
return result;
}
with ({}) {}
let arr = [];
for (var i = 0; i < 10000; i++) {
arr.push(i);
}
let start = performance.now()
for (var i = 0; i < 100000; i++) {
bar();
}
print(performance.now() - start);
There are more efficient ways to do this. For example, checking the IsNonPacked flag on the elements is probably a bit cheaper and, more importantly, can be hoisted outside the loop because it doesn't depend on the index.
Comment 1•10 months ago
|
||
So we could add a MIR which generates a instruction like https://searchfox.org/mozilla-central/source/js/src/jit/CodeGenerator.cpp#15126-15127 and add it before every place we generate the MLoadElement instruction?
| Assignee | ||
Comment 2•10 months ago
|
||
That instruction is setting the NonPacked flag when we store a hole value. We want to guard that the flag is not set, similar to GuardArrayIsPacked, but without the array-specific length == initializedLength check.
I wrote a patch for this yesterday. You can see the try run here.
Comment 3•10 months ago
|
||
Thank you so much for explaining i shall study the patch! :-)
| Assignee | ||
Comment 4•9 months ago
|
||
Updated•9 months ago
|
| Assignee | ||
Comment 5•9 months ago
|
||
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Comment 6•9 months ago
|
||
Comment 8•9 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/d38344c6778c
https://hg.mozilla.org/mozilla-central/rev/a3d1c99c9cc6
https://hg.mozilla.org/mozilla-central/rev/83453fc62def
Updated•8 months ago
|
Description
•