Skip to content

Commit

Permalink
50% faster async / Promise
Browse files Browse the repository at this point in the history
This makes promises & async take two ticks instead of three ticks.

See tc39/ecma262#1250
See tc39/ecma262#2770
See tc39/ecma262#2772

50% faster when measuring call overhead. Similar improvements for https:/v8/promise-performance-tests and when measuring with the following snippet:

```js
import { run, bench } from "mitata";

bench("sync", () => {});
bench("async", async () => {});

run();
```
  • Loading branch information
Jarred-Sumner committed May 28, 2022
1 parent 2640da9 commit b4463b6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/JavaScriptCore/builtins/PromiseOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ function resolvePromise(promise, resolution)
if (!@isObject(resolution))
return @fulfillPromise(promise, resolution);

if (@isPromise(resolution)) {
if (resolution.constructor === @Promise || resolution.constructor === @InternalPromise) {
return @performPromiseThen(resolution, @undefined, @undefined, promise);
}
}

var then;
try {
then = resolution.then;
Expand Down Expand Up @@ -312,6 +318,12 @@ function resolveWithoutPromise(resolution, onFulfilled, onRejected)
return;
}

if (@isPromise(resolution)) {
if (resolution.constructor === @Promise || resolution.constructor === @InternalPromise) {
return @performPromiseThen(resolution, onFulfilled, onRejected, @undefined);
}
}

var then;
try {
then = resolution.then;
Expand Down

0 comments on commit b4463b6

Please sign in to comment.