Performance: Sequential vs parallel async execution
HIGH IMPACT
This concept affects how fast asynchronous tasks complete and how responsive the application feels during execution.
async function fetchParallel() { const promise1 = fetchData1(); const promise2 = fetchData2(); const promise3 = fetchData3(); const results = await Promise.all([promise1, promise2, promise3]); return results; }
async function fetchSequential() { const data1 = await fetchData1(); const data2 = await fetchData2(); const data3 = await fetchData3(); return [data1, data2, data3]; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sequential async | Minimal DOM ops until all data fetched | 1 reflow after all data ready | Single paint after data update | [X] Bad |
| Parallel async | Minimal DOM ops, data ready sooner | 1 reflow after longest fetch completes | Single paint after data update | [OK] Good |