Asynchronous stack traces: why await beats .then()

Insightful post by Mathias Bynens:

The fundamental difference between await and vanilla promises is that await X() suspends execution of the current function, while promise.then(X) continues execution of the current function after adding the X 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.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.