Commit 140b8980 authored by gsathya's avatar gsathya Committed by Commit bot

[promises] Avoid creating resolving functions in

Promise.resolve

Instead of creating resolve and reject closures, directly
call ResolvePromise after creating the promise.

Using the following as a microbenchmark --
```
var b = 0;
var start = performance.now();
for (var i = 0; i < 1000000; i++) {
  Promise.resolve(1).then((val) => {
    b += val;
    if (b == 1000000) print(performance.now() - start)
  });
}
```

I see a 16.01% improvement over 5 runs with this patch.

BUG=v8:5046

Review-Url: https://codereview.chromium.org/2143553002
Cr-Commit-Position: refs/heads/master@{#38318}
parent 6cf621ec
......@@ -449,6 +449,13 @@ function PromiseResolve(x) {
}
if (IsPromise(x) && x.constructor === this) return x;
// Avoid creating resolving functions.
if (this === GlobalPromise) {
var promise = PromiseInit(new GlobalPromise(promiseRawSymbol));
var resolveResult = ResolvePromise(promise, x);
return promise;
}
var promiseCapability = NewPromiseCapability(this);
var resolveResult = %_Call(promiseCapability.resolve, UNDEFINED, x);
return promiseCapability.promise;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment