Intent to Ship: Promise.{all, race, allSettled} optimization

92 views
Skip to first unread message

Sathya Gunasekaran

unread,
Apr 25, 2019, 2:43:52 PM4/25/19
to blink-dev, v8-users, v8-...@googlegroups.com

Contact emails

gsa...@chromium.org


Explainer

https://github.com/tc39/proposal-promise-allSettled/pull/40

https://github.com/tc39/ecma262/issues/1505


Spec

https://github.com/tc39/ecma262/pull/1506/files

https://github.com/tc39/proposal-promise-allSettled/pull/40/files


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.


Risks

Interoperability and Compatibility

There is a very small risk of interop and web compatibility in the case of Promise.all and Promise.race, as we are modifying the behavior of methods that have been shipping for a while. There is no risk of interop or web compat with Promise.allSettled as it is a new proposal.


I expect the risk to be very low considering the surprising side-effecting nature of changing the resolve method *while* iterating over the argument or if there is a user installed ‘resolve’ getter that side effects.


Unfortunately it’s not possible to use counters to determine if this will break or not -- we can’t count the side effects of calling a method. We can only determine if the resolve method has been patched or not, but that’s not fully sufficient to determine the risk.


Given the very low risk of this surprising behavior, I’d like to ship this to determine if there is any breakage.

Ergonomics

N/A


Activation

N/A



Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes.


Debuggability

This doesn’t change any of the debugging functionality of Promises.


Is this feature fully tested by web-platform-tests? Link to test suite results from wpt.fyi.

V8 passes all the test262 tests: https://github.com/tc39/test262/pull/2131


Entry on the feature dashboard

https://www.chromestatus.com/feature/5171235300311040


Requesting approval to ship?

Yes


Sathya Gunasekaran

unread,
Apr 25, 2019, 2:44:57 PM4/25/19
to blink-dev, v8-...@googlegroups.com, v8-users

Adam Klein

unread,
Apr 25, 2019, 2:47:49 PM4/25/19
to Sathya Gunasekaran, blink-dev, v8-...@googlegroups.com, v8-users
Non-API owner LGTM, as this is a very low-risk change. Its only expected impact will be a performance improvement/simplification.

And a reminder to API owners to look at this, since we've just switched V8/JS features over to using the Blink Intent process.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAMd%2BM7wqinO2%3DbAMH%2BhyKzAEQowJXodfV9ioBEzemDfYDshPEg%40mail.gmail.com.

Mathias Bynens

unread,
Apr 26, 2019, 2:49:40 AM4/26/19
to v8-...@googlegroups.com, Sathya Gunasekaran, blink-dev, v8-users
Non-API owner LGTM. Optimize all the things! 

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Russell

unread,
May 2, 2019, 3:10:12 PM5/2/19
to blink-dev
LGTM1

Yoav Weiss

unread,
May 2, 2019, 3:14:07 PM5/2/19
to Alex Russell, blink-dev
LGTM2

On Thu, May 2, 2019 at 8:10 PM 'Alex Russell' via blink-dev <blin...@chromium.org> wrote:
LGTM1


--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/15bfc39c-6714-4985-ba69-5e87ceeb0756%40chromium.org.

Chris Harrelson

unread,
May 2, 2019, 3:14:17 PM5/2/19
to Alex Russell, blink-dev
LGTM2

On Thu, May 2, 2019 at 12:10 PM 'Alex Russell' via blink-dev <blin...@chromium.org> wrote:
LGTM1

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/15bfc39c-6714-4985-ba69-5e87ceeb0756%40chromium.org.

Chris Harrelson

unread,
May 2, 2019, 3:22:56 PM5/2/19
to Sathya Gunasekaran, blink-dev, v8-users, v8-...@googlegroups.com
LGTM1

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.

Philip Jägenstedt

unread,
May 6, 2019, 5:12:23 AM5/6/19
to Chris Harrelson, Sathya Gunasekaran, blink-dev, v8-users, v8-...@googlegroups.com

Benedikt Meurer

unread,
May 6, 2019, 5:15:41 AM5/6/19
to v8-dev, Chris Harrelson, Sathya Gunasekaran, blink-dev, v8-users
LGTM3

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Benedikt Meurer | Software Engineer, V8 | Google Germany GmbH | Erika-Mann-Str. 33, 80636 München 

Registergericht und -nummer: Hamburg, HRB 86891 | Sitz der Gesellschaft: Hamburg | Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle
Reply all
Reply to author
Forward
0 new messages