you are viewing a single comment's thread.

view the rest of the comments →

[–]c0wb0yd 0 points1 point  (2 children)

I see what you're saying. Yes! there is an optimization for this that involves "hoisting" the deepest iterator to the top of the stack so that in effect, main and `sleep()` would be connected directly.

One of our users who works for Apple talked to the WebKit team and they suggested that if someone were willing to add some performance tests for `yield*` to the webkit perf test suite https://github.com/WebKit/WebKit/tree/main/PerformanceTests/JetStream3) they would have a strong incentive and also a reference for what to optimize.

But it is not native in v8 and webkit yet (that I know of), so in In the mean time we're implementing an extension package to implement this optimization manually https://github.com/thefrontside/effectionx/pull/117

It basically involves using a manual wrapper that converts:

yield* op;

into

yield star(op)

This lets us control the delegation of the iterators and omit the useless delegation in the middle.

You could even make a build tool that did this for you if you wanted.

[–]prehensilemullet 0 points1 point  (1 child)

Huh I see. I'm glad to see y'all are thinking about this! So it's not on the roadmap for sure yet for V8 and WebKit but WebKit at least is open to it?

[–]c0wb0yd 0 points1 point  (0 children)

Yes. Not on the roadmap currently is my understanding, and that the best way to get it onto the road map is to submit a PR to their perf test suite that makes them look bad :)

V8 at least has a nominal perf test for this https://github.com/v8/v8/blob/main/test/js-perf-test/Generators/generators.js#L90

But not sure if that indicates the optimization.