Insightful post by Mathias Bynens:
The fundamental difference between await and vanilla promises is that
await X()
suspends execution of the current function, whilepromise.then(X)
continues execution of the current function after adding theX
call to the callback chain. In the context of stack traces, this difference is pretty significant.
The gist is that when using .then()
, the JS engine needs to capture the stack trace for future use in case things go awry.
Capturing the stack trace takes time (i.e. degrades performance); storing these stack traces requires memory. 🐌👎
Asynchronous stack traces: why await
beats .then()
→
Sidenote: Need extra arguments to prefer async/await
over promises? Read 6 Reasons Why JavaScript’s Async/Await Blows Promises Away.
Leave a comment