Open Bug 1315620 Opened 8 years ago Updated 2 years ago

Optimize out resolved promise allocation in await.

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

Tracking Status
firefox52 --- wontfix

People

(Reporter: arai, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: triage-deferred)

(separated from bug 1314055, based on bug 1315559)

https://tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await

AsyncFunctionAwait creates resolved promise from passed value, and call then on it.
if passed promise is not modified and not subclassed, we could optimize out allocation of the resolved promise, and use passed promise directly.
main concern is execution timing:
  1. it may cause the execution out of order (2 jobs vs 1 job)
  2. mis-optimization because of the passed promise or prototype can be modified between when we check the if it's optimizable and when we actually perform "then"
(In reply to Tooru Fujisawa [:arai] from comment #1)
> main concern is execution timing:
>   1. it may cause the execution out of order (2 jobs vs 1 job)
>   2. mis-optimization because of the passed promise or prototype can be
> modified between when we check the if it's optimizable and when we actually
> perform "then"

Both of these concerns apply to all potential optimizations of thenables handling, yes. My basic plan is to introduce a type of promise job that can delay itself one turn - essentially, the first time it is called it immediately re-enqueues itself. Extending that to handle thenables seems fairly straight-forward. All of this would be easier if we first change JSRuntime::enqueuePromiseJob to take a JSObject instead of a JSFunction, with an added JSAPI function ExecutePromiseJob that knows how to handle a job. This object would be a PromiseReactionRecord containing the required information.

bz tells me that changing Gecko to enable JSObjects as promise jobs instead of JSFunctions wouldn't be trivial though, so this won't happen right-away.
filed bug 1315756 for optimizing throwawayCapability out, that is in step 7
https://tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await

to be clear, this bug corresponds to step 2.
Mass wontfix for bugs affecting firefox 52.
Blocks: es6perf
Keywords: triage-deferred
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.