← Back to release summary

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

Ecosystem

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

View on chromestatus.com