Commit f1dbb12a8d1 for nodejs

commit f1dbb12a8d15379c27bed3448c811671f08f911b
Author: Ilyas Shabi <ilyas.shabi@datadoghq.com>
Date:   Sat Dec 5 16:15:51 2026 +0100

    process: skip AsyncResource in queueMicrotask when only ALS is active

    Signed-off-by: Ilyas Shabi <ilyas.shabi@datadoghq.com>
    PR-URL: https://github.com/nodejs/node/pull/67986
    Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>

diff --git a/benchmark/process/queue-microtask-breadth.js b/benchmark/process/queue-microtask-breadth.js
index c0c30a67b7e..2802b3404fe 100644
--- a/benchmark/process/queue-microtask-breadth.js
+++ b/benchmark/process/queue-microtask-breadth.js
@@ -3,9 +3,20 @@
 const common = require('../common.js');
 const bench = common.createBenchmark(main, {
   n: [4e5],
+  als: [0, 1],
 });

-function main({ n }) {
+function main({ n, als }) {
+  if (als) {
+    const { AsyncLocalStorage } = require('async_hooks');
+    // Run the benchmark inside an AsyncLocalStorage context
+    new AsyncLocalStorage().run({}, () => queue(n));
+  } else {
+    queue(n);
+  }
+}
+
+function queue(n) {
   let j = 0;

   function cb() {
diff --git a/benchmark/process/queue-microtask-depth.js b/benchmark/process/queue-microtask-depth.js
index e45c00d2c71..136f2e0c9b5 100644
--- a/benchmark/process/queue-microtask-depth.js
+++ b/benchmark/process/queue-microtask-depth.js
@@ -2,9 +2,20 @@
 const common = require('../common.js');
 const bench = common.createBenchmark(main, {
   n: [12e5],
+  als: [0, 1],
 });

-function main({ n }) {
+function main({ n, als }) {
+  if (als) {
+    const { AsyncLocalStorage } = require('async_hooks');
+    // Run the benchmark inside an AsyncLocalStorage context.
+    new AsyncLocalStorage().run({}, () => start(n));
+  } else {
+    start(n);
+  }
+}
+
+function start(n) {
   let counter = n;
   bench.start();
   queueMicrotask(onNextTick);
diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js
index c3f935cae38..8dff4fed189 100644
--- a/lib/internal/process/task_queues.js
+++ b/lib/internal/process/task_queues.js
@@ -167,8 +167,7 @@ const defaultMicrotaskResourceOpts = { requireManualDestroy: true };
 function queueMicrotask(callback) {
   validateFunction(callback, 'callback');

-  const contextFrame = AsyncContextFrame.current();
-  if (contextFrame || enabledHooksExist()) {
+  if (enabledHooksExist()) {
     const asyncResource = new AsyncResource(
       'Microtask',
       defaultMicrotaskResourceOpts,
@@ -176,7 +175,7 @@ function queueMicrotask(callback) {
     asyncResource.callback = callback;
     enqueueMicrotask(FunctionPrototypeBind(runMicrotask, asyncResource));
   } else {
-    // Fast path: no AsyncLocalStorage in use
+    // Fast path: V8's CallableTask preserves ContinuationPreservedEmbedderData.
     enqueueMicrotask(callback);
   }
 }