Emit for-of IteratorClose bytecode after the loop
Categories
(Core :: JavaScript Engine, task, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox157 | --- | fixed |
People
(Reporter: jandem, Assigned: jandem)
Details
Attachments
(3 external files)
for-of loops need to close the iterator on non-local exits. Today we handle this by emitting the IteratorClose bytecode for each non-local exit path. This has two downsides:
- The iterator closing is logically outside the try-catch but inside it in the bytecode. Handling this requires
ForOfIterClosetry notes - see Iain's beautiful ASCII-art here. - When the loop has multiple
breakorreturnstatements, we emit the iterator-close bytecode for each one separately. This becomes a problem withawaitandusingbecause we emit a lot of iterator-closing bytecode in these cases.
What we do for try-finally and (since bug 2063576) destructuring, is that we emit the IteratorClose code after the main bytecode and then jump to it. After closing the iterator we then continue the non-local exit. Iain and I were hoping this would also work for for-of loops, so I tried it and it does work nicely. This lets us remove the ForOfIterClose try note and we can share bytecode for similar non-local exits.
| Assignee | ||
Comment 1•3 months ago
|
||
This also speeds up some for-of loops with break statements because we now avoid some phis that blocked scalar replacement.
| Assignee | ||
Comment 2•3 months ago
|
||
The old code didn't handle the CatchA => CatchB => ForOf case correctly, because
it treated both catch blocks as synthetic for-of catch blocks instead of only CatchB.
This caused a debugger jit-test failure when we remove the ForOfIterClose try note
in a later patch.
| Assignee | ||
Comment 3•3 months ago
|
||
This changes for-of loops to match what finally blocks and (since bug 2063576)
array destructuring do. The non-local exit bytecode jumps to shared code emitted
after the loop, where we close the iterator and continue the non-local exit.
The patch also simplifies NonLocalExitControl::emitNonLocalJump a bit. We no
longer need the jumpingToCleanup boolean and can instead return immediately.
This lets us remove TryNoteKind::ForOfIterClose in the next patch. It also lets us
share bytecode for similar non-local exits, which matters for await and using loops
because in these cases we can emit a lot of bytecode.
Micro-benchmarks show that some for-of loops with break statements are much faster
because we now avoid some phis that prevented scalar replacement.
| Assignee | ||
Comment 4•3 months ago
|
||
Updated•3 months ago
|
Comment 6•2 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/bf70802f0b8b
https://hg.mozilla.org/mozilla-central/rev/0d3e2334b0d1
https://hg.mozilla.org/mozilla-central/rev/e4b7008841ee
Updated•2 months ago
|
Description
•