• Benedikt Meurer's avatar
    [async-await] Eliminate throwaway promise in async functions. · a840f1f8
    Benedikt Meurer authored
    The ES2017 specification contains a so-called "throwaway" promise that
    is used to specify the behavior of await in terms of PerformPromiseThen,
    but it's actually not necessary and never exposed to user code. In
    addition to that, hooking up the promise in await required a context (to
    refer to the generator object) and two closures for the reject/fulfill
    handling, which would resume the generator corresponding to the async
    function. That meant, we had to allocate 4 additional objects for every
    await.
    
    Instead of using a JSPromise plus the callbacks, this CL adds logic to
    allow PromiseReaction and PromiseReactionJobTask to carry arbitrary
    payloads and Code handlers. We use this for await to avoid the
    additional 4 objects mentioned above, and instead just have simple Code
    handlers that resume the generator (for the async function), either by
    throwing (in case of a rejection) or by resuming normally (in case of
    fulfillment).
    
    For this to work properly the JSGeneratorObject has to have a link to
    the outer promise returned by the async function, so that the catch
    prediction can still figure out what to do in case of promise rejection.
    This is done by adding a new generator_outer_promise_symbol when the
    debugger is active, which refers from the generator to the outer
    promise.
    
    With this change the doxbee-async-es2017-native test goes from around
    100.54ms to around 82.45ms, which corresponds to a ~18% reduction in
    execution time.
    
    Bug: v8:7253
    Change-Id: Iae25b3300bac351c3417be5ae687eff469b0e61f
    Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
    Reviewed-on: https://chromium-review.googlesource.com/924069Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
    Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
    Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#51334}
    a840f1f8
runtime-promise.cc 5.4 KB