-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this change be pursued for https://tc39.github.io/ecma262/#sec-performpromiseall as well?
|
It kind of seems like before this optimization lands here, there should be some consensus for making the change in the other promise methods? (Especially since allSettled can’t be polyfilled with Promise.all if there’s an inconsistency) |
That would mean blocking shipping this until we do the web compat dance for all the other methods, which seems unfortunate. |
I agree, but if we end up with a nice table of 4 Promise combinators, per the readme, but 3 of them have one observable behavior and 1 has another, that seems more unfortunate :-/ |
We have successfully made similar changes to the iterator protocol in the past without any web-compat trouble, which makes me hopeful that we'd be able to get away with these changes (to the two existing combinators) as well.
Ack, but note that instead of 3-1 it would be 2-2 (since it seems the 2 new proposals would enable the optimization @gsathya suggested). cc @anba who has a SpiderMonkey patch. |
I agree with @ljharb; at no point should this proposal specify behavior that differs from already-required common behavior in the other Promise combinators. If we can get |
Filed tc39/ecma262#1505 to track changes for I understand the spec consistency argument for having all the promise combinators have the same behavior, but I think it's worthwhile to deviate in this very minor case if it means We should try and change |
Thanks very much for opening the main spec issue! As for these new functions, I disagree that deviation is worthwhile, and would further caution against overemphasizing the significance of performance upon Promise aggegration, which can surely tolerate some inefficiency. |
Makes it consistent with https://github.com/tc39/ecma262/pull/1506/files
Ok, to summarize the above:
|
In the PerformPromise{All, Race, AllSettled} operations, the resolve property of the constructor is looked up only once. In the implementation, for the fast path, where the constructor's resolve property is untainted, the resolve function is set to undefined. Since undefined can't be a valid value for the resolve function, we can switch on it (in CallResolve) to directly call the PromiseResolve builtin. If the resolve property is tainted, we do an observable property lookup, save this value, and call this property later (in CallResolve). I ran this CL against the test262 tests locally and they all pass: tc39/test262#2131 Spec: - tc39/ecma262#1506 - tc39/proposal-promise-allSettled#40 Bug: v8:9152 Change-Id: Icb36a90b5a244a67a729611c7b3315d2c29de6e9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1574705 Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#60957}
To optimize away the
Get
andCall
of theresolve
method on theconstructor
, I'd have to check theconstructor
to see if itsresolve
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. I don't think anyone should do this in any case as it's surprising side-effecting behavior.