Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: Reduce the number of ticks in async/await #1250

Merged
merged 3 commits into from
Feb 26, 2019

Commits on Feb 26, 2019

  1. Normative: Reduce the number of ticks in async/await (tc39#1250)

    JavaScript programmers may expect that the following
    two programs are largely similar in terms of how they perform with
    respect to the ECMAScript job queue (if inside of an async function):
    
    promise.then(f);                f(await promise);
    
    However, if `promise` is a built-in promise, then these two code fragments
    will differ in the number of iterations through the job queue are taken: because
    `await` always wraps a Promise with another Promise, there are three job
    queue items enqueued and dequeued before calling `f` in the `await` example,
    whereas there is just a single item for the `then` usage.
    
    In discussions with JavaScript programmers, the number of job queue items
    in the current semantics turns out to be surprising. For example, the difference
    has become more visible in conjunction with new V8 features for Promise
    visibility and debugging, which are sometimes used in Node.js.
    
    This patch changes the semantics of await to reduce the number of
    job queue turns that are taken in the common `await` Promise case by replacing
    the unconditional wrapping with a call to PromiseResolve. Analogous changes
    are made in async iterators.
    
    The patch preserves key design goals of async/await:
    - Job queue processing remains deterministic, including both ordering and the number of jobs enqueued (which is observable by interspersing other jobs)
    - Userland Promise libraries with "then" methods ("foreign thenables") are usable within `await`, and trigger a turn of the job queue
    - Non-Promises can be awaited, and this takes a turn of the native job queue (as do all usages of `await`)
    
    Reducing the number of job queue turns also improves performance
    on multiple highly optimized async/await implementations. In a draft
    implementation of this proposal in V8 behind a flag [1]:
    - The doxbee async/await performance benchmark [2] improved with 48%
    - The fibonacci async/await performance benchmark [3] improved with 23%
    - The Hapi throughput benchmark [4] improved with 50% (when async hooks are enabled) and with 20% (when async hooks are disabled)
    
    [1] https://chromium-review.googlesource.com/c/v8/v8/+/1106977
    [2] https://github.com/bmeurer/promise-performance-tests/blob/master/lib/doxbee-async.js
    [3] https://github.com/bmeurer/promise-performance-tests/blob/master/lib/fibonacci-async.js
    [4] https://github.com/fastify/benchmarks
    MayaLekova authored and ljharb committed Feb 26, 2019
    Configuration menu
    Copy the full SHA
    a264711 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ec07f4e View commit details
    Browse the repository at this point in the history
  3. Markup: Fix handle for clause AsyncFromSyncIteratorContinuation (tc39…

    …#1250)
    
    Make the clause adhere to the naming policy as stated
    in this review comment [1].
    
    [1] tc39#1248 (comment)
    MayaLekova authored and ljharb committed Feb 26, 2019
    Configuration menu
    Copy the full SHA
    e985e41 View commit details
    Browse the repository at this point in the history