4 ms·
Negative. The scheduler is an optimisation. The alternative is to rely on VM scheduling using `process.nextTick` or `setTimeout` for every new async operation,
by Mitranim 9y ago
Negative. The scheduler is an optimisation. The alternative is to rely on VM scheduling using `process.nextTick` or `setTimeout` for every new async operation, which involves mandatory allocations and possibly other overhead. Using a custom scheduler is MUCH more efficient, which is why every decent promise implementation does it.
- pspeter3 9y agoInteresting, I would have assumed that relying on VM scheduling would be more efficient. As a corollary, are custom promises faster than native promises?
- Mitranim 9y agoYes. Some popular promise polyfills totally trash the performance of "native" promises. I don't quite remember which ones. Needless to say, Posterus also compares very well in this field.
- pspeter3 9y agoHmm, I'll have to look for benchmarks then. My general experience is that it is hard to outsmart the VM performance wise in the long run
- Mitranim 9y agoWe're not competing with VMs here. From what I hear, like many other built-ins, "native" promises in every VM are implemented in JavaScript. They're not always well done (V8 promises were really bad for a while), and pay a mandatory overhead for useless "privacy" features dictated by the spec.