Bluebird which is one of the most popular promise libraries converts entire callback APIs to promises in one go:
Promise.promisifyAll(require("fs")); // fs is now promisified and methods return promises.
(full disclosure, I'm a bluebird contributor)
Bluebird which is one of the most popular promise libraries converts entire callback APIs to promises in one go:
Promise.promisifyAll(require("fs")); // fs is now promisified and methods return promises.
(full disclosure, I'm a bluebird contributor)
It builds a function dynamically and then compiles it and lets the JIT optimize it - it incurs very little overhead.
This is impossible if your only tool is the promise constructor. That said - there are packages that do this without bluebird - like thenify.
Also note - you can use bluebird for promisification and native promises for other stuff if you'd like and it'd work seamlessly as bluebird passes the Promises/A+ test suite.
Do you have any data that shows Promise speed to be a blocker on UI performance?
Great, got data on the type of difference?
[0] https://github.com/petkaantonov/bluebird/blob/master/docs/do...
I agree! But you did answer it:
> Bluebird is mainly designed for node (V8) and promise performance can make a massive difference on the server.
If I'm sacrificing simplicity (by using a non-native Promise implementation with a very large API) because of performance improvements, I want data (proof) of these performance improvements. If you don't have the data that's fine! No harm done, I'll keep waiting until someone does.
If it takes 100ms CPU time to process 10 promises and 1 request involves creating 10 promises, the server can then only handle 100 requests per second at theoretical max.
IO time doesn't matter as much (for throughput) because IO is asynchronous so the server is free to process other requests while waiting for it. But CPU time is only being used for 1 thing at at time.
So to get e.g. 10k rps out of a node server, handling 100000 promises must take well under a second of CPU time. Looking at the benchmark results you can see how many implementations will bottleneck this.
I'm not sure I'd necessarily call ```promisifyAll()``` "blazing fast" but in all fairness it's a cost incurred up front and that's it so it's not that bad.