koajs / compose

Middleware composition utility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

promote `yield* next` instead of `yield next`

jonathanong opened this issue · comments

it's faster: tj/co#43

at least it'll work with or without it. it's an easy win. testing koa's benchmark, here's loa without yield*:

screen shot 2013-11-09 at 2 36 29 pm

with yield*:

screen shot 2013-11-09 at 2 36 57 pm

only problem is that next() should always return a generator. that's an easy fix.

i think the best thing about yield* next is that now next is explicitly a generator.

that's not even remotely enough of a gain to worry about IMO, add one console.log() per request and you take a bigger hit. If anything we could improve co's perf by adding a shared scheduler but not a huge deal really. I don't like the context switching between yield and delegation

i'm not worrying about it :P it's just free to me.

it would kinda almost be nicer if javascript would just auto-delegate when you yield a generator, maybe make yield * the inverse haha.. meh

i wish there were no stars anywhere

that too

"i wish there were no stars anywhere"

That really describes the sentiment. :)

commented

+1
Is there any significant drawbacks when using yield* like memory consumption or cpu usage?
IMO it should be not too hard, and it also has less chance to break something. So hopefully it will be finally changed.

there really isn't any downside, but it's probably not worth the cognitive overhead for new beginners, especially with async/await coming along.