• Benedikt Meurer's avatar
    [debug] Decouple async event delegate instrumentation from PromiseHooks. · b46d5ffb
    Benedikt Meurer authored
    As described in https://crbug.com/1287476, the fact that the
    AsyncEventDelegate is currently implemented on top of the PromiseHooks
    causes performance problems and makes it difficult to reason about the
    exact (observed) semantics; this is because for this we intercept every
    JSPromise creation (via PromiseHook::kInit) and walk the synchronous
    stack at that point to see if we find one of Promise#then(),
    Promise#catch() or Promise#finally() on the stack. And if we do so, we
    report that to the AsyncEventDelegate (which is implemented in the
    inspector and will then do the async stack/stepping logic on top).
    
    This CL introduces dedicated instrumentation for Promise#then(), which
    is also called from Promise#catch() and Promise#finally(), and uses that
    instrumentation for the purpose of the AsyncEventDelegate. It also
    adjusts the stack walk to not always walk the full stack (which might
    lead to wrong results when calls to Promise#then(), which itself can
    call back into user JavaScript, are found deeper in the stack), but
    instead only check the top-most builtin frames and whatever user
    JavaScript frame is underneath it.
    
    On the standalone.js (from https://crbug.com/1287476#c1), when run with
    the DevTools default of maxDepth=200, we go from around 4.00ms to around
    0.36ms. For everything that does not call Promise#then() - either
    explicitly or implicitly - or `await`s, there's now no observable
    performance impact of turning on the AsyncEventDelegate.
    
    Bug: chromium:1280519
    Fixed: chromium:1287476
    Change-Id: I4911bed146381fc46cfeefb763d6dfc32e8f6071
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3386379
    Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
    Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
    Commit-Queue: Leszek Swirski <leszeks@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#78640}
    b46d5ffb
runtime-promise.cc 7.81 KB