Closed Bug 1782677 Opened 3 years ago Closed 3 years ago

Optimize away `MakeIteratorWrapper` and/or function created inside it

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

Bug 1781061 will fix the situation around callContentFunction, iterator, and JSOp::DebugCheckSelfHosted.
After that, MakeIteratorWrapper function or the function created inside it could be optimized away.

The situation is the following:

  • "Get" operation on [Symbol.iterator] property is performed at step 4
  • We use for-of syntax to implement the step 5.e loop
  • for-of performs [Symbol.iterator] property access, but we don't want to perform it again
  • We use a wrapper that skips the [Symbol.iterator] access, and also call [Symbol.iterator] with correct this value

That's the reason why we have the wrapper object and function.
We can skip them by either:

  • (a) add self-hosted special syntax to skip [Symbol.iterator] access in for-of, but receive it
  • (b) implement the loop with while loop, instead of for-of

https://searchfox.org/mozilla-central/rev/14781effaa15c12b1652beb75f021489567bad8f/js/src/builtin/Array.js#801-803,816-817,822-823,879,885,888-891

    // Step 4.
    // Inlined: GetMethod, steps 1-2.
    var usingIterator = items[GetBuiltinSymbol("iterator")];
...
        // Step 5.c.
        var iterator = MakeIteratorWrapper(items, usingIterator);
...
        // Step 5.e
        for (var nextValue of allowContentIter(iterator)) {
...
function MakeIteratorWrapper(items, method) {
...
    return {
...
        [GetBuiltinSymbol("iterator")]: function IteratorMethod() {
            return callContentFunction(method, items);
        },
    };
Blocks: 1783186
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/07d6704acf75 Optimize away extra object and function for already-retrieved iterator method in for-of in self-hosted JS. r=jandem
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 105 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: