why is async-await much slower than promises when running them together
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Understanding Async-Await and Promises in JavaScript
JavaScript allows developers to handle asynchronous operations efficiently using both `Promises` and the `async-await` syntax. While these two constructs are integral to modern JavaScript development, there are scenarios where combining them could lead to slower execution. This article delves into the reasons why `async-await` might be slower than `Promises` when used together and offers a technical explanation supported by examples.
Promises and Async-Await: A Brief Overview
Promises
A `Promise` is an object representing the eventual completion or failure of an asynchronous operation. It can be in one of three states: `pending`, `fulfilled`, or `rejected`. Promises offer methods like `.then()`, `.catch()`, and `.finally()` to handle the outcomes, enabling the chaining of asynchronous operations.
Async-Await
Introduced in ECMAScript 2017, `async-await` allows developers to write asynchronous code in a more synchronous fashion. It is often considered more readable and easier to work with, especially in complex scenarios involving multiple async operations. The `async` keyword is used to declare an asynchronous function, which implicitly returns a `Promise`. Within this function, the `await` keyword can pause the execution until the passed `Promise` resolves.
Performance Comparison Between Async-Await and Promises
Synchronous Execution of Async Code
Despite the apparent simplicity and readability of `async-await`, when `await` is used within a loop or in scenarios requiring multiple sequential asynchronous operations, the execution can be slower compared to equivalent `Promise`-based code. This is primarily due to how JavaScript handles these asynchronous constructs:
- Promise Chaining: Promises can be chained using `.then()` and this chaining can often execute asynchronously in a way that doesn't block further processing of code.
- Await Suspension: When `await` is used, JavaScript pauses the execution of the surrounding function until the awaited `Promise` is resolved. This can introduce a synchronous-like execution pattern, which may not fully utilize JavaScript's potential for concurrency.
Example Scenario
Consider a scenario where multiple asynchronous operations need to execute in sequence:
Using Async-Await:
- Use `Promises` for situations where multiple asynchronous tasks can run concurrently and don't depend on each other.
- Use `async-await` for improved readability and scenarios that genuinely require sequential execution of tasks.
Related reading
- Why is builtin sorted slower for a list containing descending numbers if each number appears twice consecutively?
- Why is Clickhouse slower than PostgreSQL?
- Why is code behavior different in release debug mode?
- Why is .Contains slow? Most efficient way to get multiple entities by primary key?
- Why is async required on methods that call async methods?
- Why is async/await not working in my ASP.net 5 Console Application?
- Why is DarkGray lighter than Gray?
- Why is double.NaN not equal to itself?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.