• Benedikt Meurer's avatar
    [builtins] Unify PerformPromiseThen and optimize it with TurboFan. · a582199c
    Benedikt Meurer authored
    This creates a uniform PerformPromiseThen builtin, which performs the
    operation with the same name from the spec, except that it expects the
    handlers to be either undefined or callable already, since this is only
    relevant for a single callsite (namely Promise.prototype.then).
    
    Introduce a matching operator JSPerformPromiseThen into TurboFan, which
    represents this operation and removes the additional checks in case of
    Promise.prototype.then based on the information we can derived from the
    receiver maps.
    
    This yields a nice 20-25% improvement on Promise.prototype.then, as
    illustrated by the following micro-benchmark
    
    ```js
    const N = 1e7;
    function inc(x) { return x + 1; }
    function chain(promise) {
      return promise.then(inc).then(value => {
          if (value < N) chain(Promise.resolve(value));
        });
    }
    console.time('total');
    chain(Promise.resolve(0));
    setTimeout(console.timeEnd.bind(console, 'total'));
    ```
    
    which goes from around 1230ms to 930ms with this patch.
    
    Bug: v8:7253
    Change-Id: I5712a863acdbe7da3bb8e621887c7b952148c51a
    Reviewed-on: https://chromium-review.googlesource.com/899064Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
    Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
    Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#51071}
    a582199c
typer.cc 66.9 KB