sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
1.84k stars 99 forks source link

Improve performance #47

Closed sindresorhus closed 3 years ago

sindresorhus commented 3 years ago

By using a queue data structure.

Closes #46

neverendingqs commented 3 years ago

LGTM. FYI, running the same perf scenario in #46 results in a runtime of ~340 ms.

const limit = plimit(10000000);
const start = Date.now();
await Promise.all([...Array(100000)].map(_ => limit(async () => Promise.resolve())));
console.log(Date.now() - start, 'plimit');
sindresorhus commented 3 years ago

The extra 40ms is probably because I'm using classes and yallist uses plain functions. Doesn't matter though. V8 will eventually make it as fast or faster.

sindresorhus commented 3 years ago

Thanks for bringing this up and testing 🙌🏻