summaryrefslogtreecommitdiff
path: root/core/01_core.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-14 16:21:06 +0200
committerGitHub <noreply@github.com>2023-06-14 16:21:06 +0200
commit5ef225853c0f81ba0a7d1ce888ab3b2d283eae0a (patch)
tree169c5e4f2f428bf3782351c5b9563febaa100dfd /core/01_core.js
parent691ef2cc6a1144d17d6ffbc7f4ed88ba424ec3c0 (diff)
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
Diffstat (limited to 'core/01_core.js')
-rw-r--r--core/01_core.js9
1 files changed, 9 insertions, 0 deletions
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;
}