Create resolved promises for primitives faster
Categories
(Core :: JavaScript Engine, task)
Tracking
()
People
(Reporter: mgaudet, Assigned: mgaudet)
References
(Blocks 1 open bug)
Details
Attachments
(2 external files)
We can fast path the resolution of primitives when we have the original promise constructor
Updated•3 hours ago
|
| Assignee | ||
Comment 1•2 hours ago
|
||
NewPromiseCapability checks whether C is the current realm's original Promise
constructor to know that constructing a promise with it is unobservable. Name
that check so that a following patch can reuse it.
No behaviour change.
Updated•2 hours ago
|
| Assignee | ||
Comment 2•2 hours ago
|
||
PromiseResolve(C, x) with the current realm's %Promise% and a primitive x
creates a pending promise, then goes through CallPromiseResolveFunction,
CallDefaultPromiseResolveFunction, ResolvePromiseInternal and
FulfillMaybeWrappedPromise only to fulfill it with x and trigger an empty
reaction list. None of that is observable: constructing %Promise% isn't, and
a primitive can't be a thenable. Create the promise already fulfilled instead.
Devtools see the same promise as before. It is created by
CreatePromiseObjectWithoutResolutionFunctions, as NewPromiseCapability would
have done, so it records the same allocation site. It is settled through
SettlePromise, as ResolvePromise would have done, so the resolution site is
recorded the same way: SettlePromise's stack argument is only for passing a
rejection's exception stack, and for a fulfillment, then as now, it is null and
PromiseDebugInfo::setResolutionInfo captures the current stack instead. The old
path resolved the promise synchronously too, so that stack is the same one, of
Promise.resolve's caller.
Besides Promise.resolve this is reached by the Promise combinators for
primitive elements, Promise.try, the self-hosted PromiseResolve intrinsic
(Promise.prototype.finally), async-from-sync iterators,
JS::CallOriginalPromiseResolve, the Debugger and wasm JSPI.
On JetStream doxbee-promise in the shell this is a further 5.8% improvement on
top of the preceding patches (35.75 ms to 33.59 ms per iteration).
Description
•