2

I have a fairly big project in node.js version 7. I am planning to switch to node 8.9 LTS and replace Promise callbacks with async await. The project demands high performance machines and there are lots of high memory consuming operations. So the question is, will using `async await drop the project's performance ?

I do not have enough time to actually upgrade node and promises to async await and compare the refactored code with the previous version of the project. So any information about performance drops or rises while switching from promise to async await will be helpful

Prasanna
  • 4,125
  • 18
  • 41
  • 3
    isn't async/await just syntactic sugar for promises? – FCin Dec 20 '17 at 07:16
  • @FCin as far as I know it is, but I was just wondering if there are extra things that could impact the performace – Prasanna Dec 20 '17 at 07:17
  • 1
    See [Performance of native ES2015 promises and ES2017 async functions in Node.js v8](https://kyrylkov.com/2017/04/25/native-promises-async-functions-nodejs-8-performance/) – jfriend00 Dec 20 '17 at 10:10
  • @jfriend00 this does have performance comparison, but only for node version 8.4.0, can you provide a similar thing that compares things with version 8.9.0 ? – Prasanna Dec 20 '17 at 11:21
  • @Prasanna - That's not my article - I'm just sharing it with you. I don't have a similar reference for v8.9.0. I think all the test cases are linked there, perhaps you could run it yourself? – jfriend00 Dec 20 '17 at 11:25
  • The performance certainly will be different as the engine does different things. While only tests can show which is faster, it is expected that `async`/`await` can be optimised better by avoiding explicit method calls, instantiation of promise objects and callback closures. Of course an async function needs to be split similarly so that it can run in multiple steps, but this can happen behind the scenes. – Bergi Dec 20 '17 at 18:32

1 Answers1

7

Javascript will interpret the async/await syntax just like a normal Promise callback from the computers point of view. Javascript will handle it the same way as a normal Promise callback.

Therefor there should be no performance differences between the two. It's basically just helps make your code cleaner and easier to read and understand. But no fundemntal differences between the two.

Charlie Fish
  • 18,491
  • 19
  • 86
  • 179
  • 2
    Could you drop in a link to the official documentation that backs your answer ? – Prasanna Dec 20 '17 at 07:22
  • 3
    @Prasanna Javascript doesn't have a lot of "official documentation". I would encourage you to take a look [here](https://stackoverflow.com/questions/46481709/performance-guidelines-for-async-await-in-node-version-8). `try/catch in an async function is just syntatic sugar over a Promise .then and .catch methods, and performance is therefore determined by the underlying Promise implementation.` – Charlie Fish Dec 20 '17 at 07:30
  • 1
    Javascript has plenty of official documentation (so that's a bit of a misnomer to say that) - it's called the EcmaScript specification. What Javascript does not have is much official documentation that documents the individual implementations of the EcmaScript specification and that's where performance-related things would be found (in the actual implementations). – jfriend00 Dec 20 '17 at 10:34
  • @jfriend00 You are correct. When I think of official documentation I think end to end full, complete documentation. You are totally correct and I should have been more specific about what I meant. – Charlie Fish Dec 20 '17 at 10:37