perf(core): drop the per-op .catch wrapper promise#36155
Open
bartlomieju wants to merge 1 commit into
Open
Conversation
Every pending async op allocated two promises: the op promise plus a derived promise from PromisePrototypeCatch(promise, __opRejectHandler) whose only job was to recapture the error stack (stripping internal event loop frames) on the rare rejection path. This doubled the promise objects the GC sweeps per in-flight op and registered promise-reaction machinery on every op. Return the raw op promise (still carrying promiseIdSymbol) and drop the recapture. On the async op microbench this is ~6.5% faster across all tick-path ops (e.g. op_async_void_deferred 429.5k -> 401.3k ns/iter for 1000 ops), plus one fewer promise + reaction per in-flight op. The recapture only ever affected a *bare* op stub awaited directly (no JS wrapper): every real Deno async API (Deno.readFile, fetch, ...) is an async function that awaits the op, so V8's async stack traces already include the call site without the recapture. Verified caught, uncaught, and dynamic-import error stacks via the CLI are unchanged. Updates the one raw-runtime test that exercised the bare-op pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every pending async op currently allocates two promises: the op promise created in
setPromise, plus a second, derived promise fromPromisePrototypeCatch(promise, __opRejectHandler)whose only purpose is to recapture the error stack (stripping internal event-loop frames) on the rare rejection path. This doubles the promise objects the GC sweeps per in-flight op and registers promise-reaction machinery on every op.This PR returns the raw op promise (still carrying
promiseIdSymbol, sorefOp/unrefOpkeep working) and drops the recapture.Impact
~6.5% faster across all tick-path ops on the async op microbench (
libs/core/benches/ops/async.rs), measured back-to-back:op_async_void_deferredop_async_void_deferred_nofastop_async_void_lazyop_async_yield_deferredop_async_yield_lazy_nofastOne fewer promise + reaction allocated per in-flight async op → less GC pressure on op-heavy servers.
Stack traces
The recapture only ever affected a bare op stub awaited directly (no JS wrapper). Every real Deno async API (
Deno.readFile,fetch, …) is anasyncfunction that awaits the op, so V8's async stack traces already include the call site without the recapture. Verified caught, uncaught, and dynamic-import error stacks viadeno runare byte-identical to before.The one raw-runtime test that exercised the bare-op pattern (
test_dynamic_import_module_error_stack) is updated: it now asserts on theawait import(...)site inmain.jsrather than the innermost bare-op frame. The user-facing #20034 guarantee stays covered by the CLI specserror_023_stack_asyncandfetch_async_error_stack(both pass).Tests
cargo test -p deno_core(441/441 relevant, incl. updated dynamic-import stack test)error_02*stack tests,fetch_async_error_stack, promise/rejection tests — all pass