Promise.{all, race, allSettled} optimization
- Category
- JavaScript
- Type
- New or changed feature
- Status
- In development (Chrome In development)
- Intent stage
- Start prototyping
Summary
Promise.{all, race, allSettled} lookup the constructor of the receiver on every iteration of the loop. Instead, this change makes the lookup happen only once outside the loop.
Motivation
To optimize away the Get and Call of the resolve method on the constructor, I'd have to check the constructor to see if its resolve method has been modified or not. If it's not been modified, I can directly call (or even inline) the builtin %PromiseResolve%, saving the lookup and call overhead for faster performance. Without this patch, I would have to check against the constructor for every iteration of the loop before going to the fast path. With this patch, I can do a check against the constructor just once at the beginning. The change in behavior with this patch is that if you modify the constructor's resolve property in the middle of iterating the iterable argument, then it is not observed.
Standards & signals
- Firefox: No signal
- Safari: No signal
- Web developers: No signals
- Tracking bug: https://bugs.chromium.org/p/v8/issues/detail?id=9152
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=promise-all-race-allsettled-optimization
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+Promise.%7Ball%2C%20race%2C%20allSettled%7D%20optimization
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=Promise.%7Ball%2C%20race%2C%20allSettled%7D%20optimization
- Baseline status: https://webstatus.dev/?q=Promise.%7Ball%2C%20race%2C%20allSettled%7D%20optimization
Docs: https://github.com/tc39/ecma262/pull/1506/files https://github.com/tc39/proposal-promise-allSettled/pull/40/files
Explainers: https://github.com/tc39/proposal-promise-allSettled/pull/40 https://github.com/tc39/ecma262/issues/1505