Course contentsShow
← JavaScript
Lesson 1307 of 2,72329. PromisesFree lesson

Parallel vs All: Performance Considerations

Compare firing promises in parallel manually versus using Promise.all for concurrent execution.

Parallel vs All: Performance Considerations

You'll learn: How firing promises "in parallel" manually compares to using Promise.all for concurrent execution.

The Core Idea

When you have multiple asynchronous operations that don't depend on each other, you want them to run concurrently (not waiting for one to finish before starting the next). There are two common patterns:

  1. Manual parallel firing: Create all promises immediately, then await them separately
  2. Using Promise.all: Pass all promises to Promise.all and await the result

Both approaches start all operations at the same time, but they differ in ergonomics and error handling.

Manual Parallel Firing

const promise1 = fetch('/api/users');
const promise2 = fetch('/api/posts');
const promise3 = fetch('/api/comments');

// All three requests started immediately
const users = await promise1;
const posts = await promise2;
const comments = await promise3;

This works, but you still await them sequentially at the end. If promise1 takes 2 seconds and promise2 takes 1 second, you wait 2 seconds before getting posts.

Using Promise.all

const [users, posts, comments] = await Promise.all([
  fetch('/api/users'),
  fetch('/api/posts'),
  fetch('/api/comments')
]);

This starts all operations simultaneously and resolves when all complete. You get all results at once after the slowest operation finishes.

Performance Considerations

  • Speed: Both start operations concurrently, so total time is roughly the same (determined by the slowest operation)
  • Readability: Promise.all is cleaner and more declarative
  • Error handling: Promise.all short-circuits on the first rejection; manual firing continues all operations even if one fails early
  • Memory: Negligible difference for small counts; both hold promises in memory

Key Takeaway: Use Promise.all for cleaner code and coordinated error handling when running independent promises concurrently; manual firing offers more control over individual error scenarios but requires more code.