From 430b63c2c4d6567a77e77980058ef13b45a9f30e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Sat, 16 Sep 2023 07:48:31 +0200 Subject: perf: improve async op santizer speed and accuracy (#20501) This commit improves async op sanitizer speed by only delaying metrics collection if there are pending ops. This results in a speedup of around 30% for small CPU bound unit tests. It performs this check and possible delay on every collection now, fixing an issue with parent test leaks into steps. --- ext/broadcast_channel/01_broadcast_channel.js | 5 +++-- ext/fetch/26_fetch.js | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/broadcast_channel/01_broadcast_channel.js b/ext/broadcast_channel/01_broadcast_channel.js index ab315eaa6..e5e4169b6 100644 --- a/ext/broadcast_channel/01_broadcast_channel.js +++ b/ext/broadcast_channel/01_broadcast_channel.js @@ -15,8 +15,9 @@ import DOMException from "ext:deno_web/01_dom_exception.js"; const primordials = globalThis.__bootstrap.primordials; const { ArrayPrototypeIndexOf, - ArrayPrototypeSplice, ArrayPrototypePush, + ArrayPrototypeSplice, + PromisePrototypeThen, Symbol, Uint8Array, } = primordials; @@ -70,7 +71,7 @@ function dispatch(source, name, data) { // for that reason: it lets promises make forward progress but can // still starve other parts of the event loop. function defer(go) { - setTimeout(go, 1); + PromisePrototypeThen(core.ops.op_void_async_deferred(), () => go()); } class BroadcastChannel extends EventTarget { diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js index 311a197a8..f1c771dc0 100644 --- a/ext/fetch/26_fetch.js +++ b/ext/fetch/26_fetch.js @@ -284,6 +284,9 @@ async function mainFetch(req, recursive, terminator) { cause: requestSendError, }); } + if (requestBodyRid !== null) { + core.tryClose(requestBodyRid); + } throw err; } finally { if (cancelHandleRid !== null) { -- cgit v1.2.3