Support scalar replacement of array iterator objects
Categories
(Core :: JavaScript Engine: JIT, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox101 | --- | fixed |
People
(Reporter: anba, Assigned: anba)
References
(Blocks 1 open bug)
Details
Attachments
(6 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
To reproduce:
- Execute below test case with
IONFLAGS=logs - Run
iongraph --final /tmp/ion.json. - Observe that the iterator object wasn't scalar replaced.
function g() {
var a = [1, 2];
var r = 0;
for (var v of a) r += v;
return r;
}
function f() {
with ({});
let r = 0;
for (let i = 0; i < 100_000; ++i) {
r += g();
}
print(r);
}
with ({});
for (let i = 0; i < 5; ++i) f();
| Assignee | ||
Comment 1•3 years ago
|
||
GuardToArrayIterator in ArrayIteratorNext blocks scalar replacement of the
array iterator object because GuardToClass isn't handled.
| Assignee | ||
Comment 2•3 years ago
|
||
var obj; is equivalent to var obj = undefined;. This leads to creating a
phi-node, because obj can be either undefined or the this-value. If we
instead initialise var obj = this;, we can ensure that we see only object-typed
definitions during scalar replacement and it ensures we don't emit spurious
MBox instructions for the phi-node input.
Depends on D144290
| Assignee | ||
Comment 3•3 years ago
|
||
Pass the object instruction in preparation for the next part.
Depends on D144291
| Assignee | ||
Comment 4•3 years ago
|
||
The guard pattern:
var obj = this;
if (!IsObject(obj) || (obj = GuardToArrayIterator(obj)) === null) {
return callFunction(CallArrayIteratorMethodIfWrapped, this,
"ArrayIteratorNext");
}
creates a phi-node for obj. We can replace this phi-node when all its inputs
are equal to the iterator object we try to scalar replace.
Depends on D144292
| Assignee | ||
Comment 5•3 years ago
|
||
Scalar replacement for iterator objects requires to support this code:
(obj = GuardToArrayIterator(obj)) === null
Depends on D144293
| Assignee | ||
Comment 6•3 years ago
|
||
This is the last remaining instruction which needs to be supported for scalar
replacement of iterator objects.
Depends on D144294
Comment 7•3 years ago
•
|
||
Thank you for these patches!
I worked on the array side of it in the past and this got regressed many times since the removal of AWFY micro-benchmarks that were checking performance differences between C-style loops and for-of loops.
Comment 9•3 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/0b22cda4d2fd
https://hg.mozilla.org/mozilla-central/rev/6b96d9037d34
https://hg.mozilla.org/mozilla-central/rev/ff95904bc09e
https://hg.mozilla.org/mozilla-central/rev/c4a0be613d2d
https://hg.mozilla.org/mozilla-central/rev/9be298355200
https://hg.mozilla.org/mozilla-central/rev/460d0aadbf1e
Description
•