is an iterator allowed to reuse the same "state" object?

Jason Orendorff jason.orendorff at gmail.com
Fri May 1 18:55:46 UTC 2015


On Wed, Apr 29, 2015 at 5:41 PM, Andreas Rossberg <rossberg at google.com> wrote:
>> I'm inferring your comment about generator optimization hardship has to do
>> with a function that yields -- whose CFG has multiple entry points and whose
>> activation record must live in the heap.
>
> Yes, the biggest challenge perhaps is not even generator CFGs per se, but
> getting inlining to work with them, which is necessary to take advantage of
> escape analysis.

Since the objects to be eliminated here are not created in the body of
the generator-function, an implementation could create those objects
in an inline-able .next() method, and thus eliminate the object even
if none of the generator code can be inlined. Pseudocode:

    Generator.prototype.next = function next(arg) {
        var value = INTERNALS.runGenerator(this, arg);
        var done = INTERNALS.generatorIsDone(this);
        return {value, done};
    };

But this too can interfere with other optimizations. Your broader
point about generator optimization certainly stands.

-j


More information about the es-discuss mailing list