From 5ef225853c0f81ba0a7d1ce888ab3b2d283eae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 14 Jun 2023 16:21:06 +0200 Subject: perf: don't run microtask checkpoint if macrotask callback did no work (#19492) Most of the time there's no firing timers, nor pending promise rejections, so it's wasteful to run microtask checkpoint additionally twice on each tick of the event loop. Closes https://github.com/denoland/deno/issues/18871 Ref https://github.com/denoland/deno/issues/19451 --- runtime/js/99_main.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'runtime/js') diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 8fd9a6bd9..511368141 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -351,6 +351,12 @@ function promiseRejectCallback(type, promise, reason) { } function promiseRejectMacrotaskCallback() { + // We have no work to do, tell the runtime that we don't + // need to perform microtask checkpoint. + if (pendingRejections.length === 0) { + return undefined; + } + while (pendingRejections.length > 0) { const promise = ArrayPrototypeShift(pendingRejections); const hasPendingException = ops.op_has_pending_promise_rejection( -- cgit v1.2.3