Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm fairly sure it's not Promises that are actually the heavy part but the `await` keyword as used in the `for await` loop. That's because await tries to preserve the call stack for debugging, making it a relatively high-level expensive construct from a perf perspective where a promise is a relatively low-level cheap one.

So if you're going to flatten everything into one stream then you can't have a for loop implementation that defensively awaits on every step, or else it'll be slooooooooow. That's my proposal for the change to the language is a syntax like

  for await? (value of stream) {
  }
which would only do the expensive high-level await when the underlying protocol forced it to by returning a promise-valued step.
 help



Async call stacks is an optional feature when the devtools is open. There shouldn't be overhead from await like that?

It's awfully hard to know, and I am not myself sure.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: