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 --- core/01_core.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core') diff --git a/core/01_core.js b/core/01_core.js index 13aa17c7e..d4a6508cb 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -187,7 +187,16 @@ const cb = macrotaskCallbacks[i]; while (true) { const res = cb(); + + // If callback returned `undefined` then it has no work to do, we don't + // need to perform microtask checkpoint. + if (res === undefined) { + break; + } + ops.op_run_microtasks(); + // If callback returned `true` then it has no more work to do, stop + // calling it then. if (res === true) { break; } -- cgit v1.2.3