Open Bug 2098729 Opened 3 hours ago Updated 2 hours ago

Create resolved promises for primitives faster

Categories

(Core :: JavaScript Engine, task)

task

Tracking

()

ASSIGNED

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

Summary: Create resolved promises for primivites faster → Create resolved promises for primitives faster

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.

Assignee: nobody → mgaudet
Status: NEW → ASSIGNED

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).

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: