0
0
Node.jsframework~8 mins

Promise.race and Promise.allSettled in Node.js - Performance & Optimization

Choose your learning style9 modes available
Performance: Promise.race and Promise.allSettled
MEDIUM IMPACT
This concept affects how asynchronous operations impact page responsiveness and resource usage during concurrent tasks.
Handling multiple asynchronous tasks and responding as soon as one finishes
Node.js
await Promise.race([task1(), task2(), task3()]); // resolves or rejects as soon as one task settles
Returns as soon as the first promise settles, improving responsiveness and reducing wait time.
📈 Performance Gainreduces blocking time, improves INP by responding faster
Handling multiple asynchronous tasks and responding as soon as one finishes
Node.js
await Promise.allSettled([task1(), task2(), task3()]); // waits for all tasks to finish
This waits for all tasks to complete even if you only need the first result, delaying response time.
📉 Performance Costblocks interaction until all promises settle, increasing INP
Performance Comparison
PatternAsync Wait TimeUI ResponsivenessResource UsageVerdict
Promise.allSettled for first resultLong (waits all)Low (delayed)High (all tasks run fully)[X] Bad
Promise.race for first resultShort (first settles)High (fast response)Moderate (tasks still run)[OK] Good
Promise.all for all successMedium (waits all success)Medium (may reject early)High (may retry)[!] OK
Promise.allSettled for all resultsLong (waits all)High (stable UI)Moderate (no retries)[OK] Good
Rendering Pipeline
Async promise handling affects the JavaScript execution and event loop stages, influencing when UI updates can occur.
JavaScript Execution
Event Loop
Rendering
⚠️ BottleneckJavaScript Execution blocking UI updates while waiting for promises
Core Web Vital Affected
INP
This concept affects how asynchronous operations impact page responsiveness and resource usage during concurrent tasks.
Optimization Tips
1Use Promise.race to improve responsiveness by reacting to the first settled promise.
2Use Promise.allSettled to get results from all promises without early rejection.
3Avoid Promise.all if you need full results and want to prevent retries or UI flicker.
Performance Quiz - 3 Questions
Test your performance knowledge
Which Promise method returns as soon as the first promise settles, improving responsiveness?
APromise.all
BPromise.allSettled
CPromise.race
DPromise.resolve
DevTools: Performance
How to check: Record a performance profile while running async tasks; look at the JavaScript call stacks and event loop delays.
What to look for: Check for long blocking times in JS execution and delayed UI updates indicating slow promise resolution.