Posts

« All Blogs

Person gesturing toward large computer screen

Performance implications of misunderstanding Node.js promises

https://eng.lifion.com/promise-allpocalypse-cfb6741298a7

Promise.allpocalypse

The performance implications of misunderstanding Node.js promises

Ali Yousuf

Ali Yousuf

Jan 22 · 8 min read

for…of over unknown collection with await in loop
Promise.all() on an entire unknown collection

Benchmarking unbounded promise scenarios

╔═══════════════╦══════════════════════════════════╗
║     Test      ║ Average Execution Time (Seconds) ║
╠═══════════════╬══════════════════════════════════╣
║ await-for-of  ║                            6.943 ║
║ bluebird-map  ║                            4.550 ║
║ for-of        ║                            6.745 ║
║ p-limit       ║                            4.523 ║
║ promise-all   ║                            4.524 ║
║ promise-limit ║                            4.457 ║
╚═══════════════╩══════════════════════════════════╝
for…of test code
for await…of test code
Image for post

Image for post

Image for post

Image for post

Clinic.js doctor output for for await…of and for…of, respectively
Image for post

Image for post

Image for post

Image for post

Clinic.js bubbleprof output for for await…of and for…of, respectively
Promise.all() test code
Image for post

Image for post

Clinic.js doctor output for Promise.all()

Promise chain execution order example
Async chain execution order example
Bluebird.map() with concurrency limit test code
Image for post

Image for post

Clinic.js doctor output for Bluebird.map() with concurrency limit
promise-limit module test code
Image for post

Image for post

Clinic.js doctor output for the promise-limit module
p-limit module test code
Image for post

Image for post

Clinic.js Doctor output for the p-limit module

Conclusion