From 7723487edb9540b8e7444492820408840267c037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 4 Oct 2025 14:47:52 +0200 Subject: [PATCH 1/3] lib: remove redundant destroyHook checks --- lib/internal/async_hooks.js | 2 +- lib/internal/process/task_queues.js | 3 +-- lib/internal/timers.js | 10 +++------- lib/timers.js | 9 ++------- .../fixtures/errors/async_error_nexttick_main.snapshot | 2 +- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 5f28ea6a0e8193..46ee92a7bb39c4 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -532,7 +532,7 @@ function emitAfterScript(asyncId) { function emitDestroyScript(asyncId) { // Return early if there are no destroy callbacks, or invalid asyncId. - if (!hasHooks(kDestroy) || asyncId <= 0) + if (!hasHooks(kDestroy) || !(asyncId > 0)) return; async_wrap.queueDestroyAsyncId(asyncId); } diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index c7194977ba9db0..6670113fa89659 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -94,8 +94,7 @@ function processTicksAndRejections() { } } } finally { - if (destroyHooksExist()) - emitDestroy(asyncId); + emitDestroy(asyncId); } emitAfter(asyncId); diff --git a/lib/internal/timers.js b/lib/internal/timers.js index f603725a7bfa41..9c7366d6ca772f 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -92,7 +92,6 @@ const { getDefaultTriggerAsyncId, newAsyncId, initHooksExist, - destroyHooksExist, // The needed emit*() functions. emitInit, emitBefore, @@ -508,8 +507,7 @@ function getTimerCallbacks(runNextTicks) { } finally { immediate._onImmediate = null; - if (destroyHooksExist()) - emitDestroy(asyncId); + emitDestroy(asyncId); outstandingQueue.head = immediate = immediate._idleNext; } @@ -585,8 +583,7 @@ function getTimerCallbacks(runNextTicks) { if (timer[kRefed]) timeoutInfo[0]--; - if (destroyHooksExist()) - emitDestroy(asyncId); + emitDestroy(asyncId); } continue; } @@ -621,8 +618,7 @@ function getTimerCallbacks(runNextTicks) { if (timer[kRefed]) timeoutInfo[0]--; - if (destroyHooksExist()) - emitDestroy(asyncId); + emitDestroy(asyncId); } } diff --git a/lib/timers.js b/lib/timers.js index de28534b93586e..f6a2f74f5ec2c7 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -63,7 +63,6 @@ let timersPromises; let timers; const { - destroyHooksExist, // The needed emit*() functions. emitDestroy, } = require('internal/async_hooks'); @@ -78,9 +77,7 @@ function unenroll(item) { if (item[kHasPrimitive]) delete knownTimersById[item[async_id_symbol]]; - // Fewer checks may be possible, but these cover everything. - if (destroyHooksExist() && item[async_id_symbol] !== undefined) - emitDestroy(item[async_id_symbol]); + emitDestroy(item[async_id_symbol]); L.remove(item); @@ -239,9 +236,7 @@ function clearImmediate(immediate) { } immediate[kRefed] = null; - if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) { - emitDestroy(immediate[async_id_symbol]); - } + emitDestroy(immediate[async_id_symbol]); immediate._onImmediate = null; diff --git a/test/fixtures/errors/async_error_nexttick_main.snapshot b/test/fixtures/errors/async_error_nexttick_main.snapshot index c5ccba996a38cc..0034454e590ab5 100644 --- a/test/fixtures/errors/async_error_nexttick_main.snapshot +++ b/test/fixtures/errors/async_error_nexttick_main.snapshot @@ -1,7 +1,7 @@ Error: test at one (*fixtures*async-error.js:4:9) at two (*fixtures*async-error.js:17:9) - at process.processTicksAndRejections (node:internal*process*task_queues:105:5) + at process.processTicksAndRejections (node:internal*process*task_queues:104:5) at async three (*fixtures*async-error.js:20:3) at async four (*fixtures*async-error.js:24:3) at async main (*async_error_nexttick_main.js:7:5) From 32376a5797cf577cd92b8aef22879f650cdcb0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 4 Oct 2025 17:43:52 +0200 Subject: [PATCH 2/3] lint --- lib/internal/process/task_queues.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index 6670113fa89659..bec1fd8bd468ba 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -27,7 +27,6 @@ const { getDefaultTriggerAsyncId, newAsyncId, initHooksExist, - destroyHooksExist, emitInit, emitBefore, emitAfter, From 0255b2eb7460186bfd6999afff345e370bf22822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 4 Oct 2025 18:52:13 +0200 Subject: [PATCH 3/3] fix snapshot --- test/fixtures/errors/async_error_nexttick_main.snapshot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/errors/async_error_nexttick_main.snapshot b/test/fixtures/errors/async_error_nexttick_main.snapshot index 0034454e590ab5..5c2e6e1558076c 100644 --- a/test/fixtures/errors/async_error_nexttick_main.snapshot +++ b/test/fixtures/errors/async_error_nexttick_main.snapshot @@ -1,7 +1,7 @@ Error: test at one (*fixtures*async-error.js:4:9) at two (*fixtures*async-error.js:17:9) - at process.processTicksAndRejections (node:internal*process*task_queues:104:5) + at process.processTicksAndRejections (node:internal*process*task_queues:103:5) at async three (*fixtures*async-error.js:20:3) at async four (*fixtures*async-error.js:24:3) at async main (*async_error_nexttick_main.js:7:5)