GeezerVison is showing github.com — src: skip the async id stack when nobody sees it by nigrosimone · Pull Request #66511 · nodejs/node
Conversation
nigrosimone
commented
Oct 4, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
With no async hook and no executionAsyncResource() user, every InternalCallbackScope pushes and pops the async ids on the stack, only for executionAsyncId() and triggerAsyncId() to read the top. This swaps the two ids in place instead: they are all that those two and process.nextTick() read, so the readers pay nothing.
executionAsyncResource() is the only reader of the stack. The scopes that skip it form a chain in AsyncHooks, counted in a new field kLazyScopes, and JS asks C++ for the innermost one only while that count is not zero. The checks for a corrupted stack stay: test/async-hooks test-improper-order and test-emit-*-on-destroyed fail without them, because the main script runs in a scope that starts before any hook.
compare.js on napi/make_callback, 30 runs, Linux x64, one core, on main (3e5c8af, with #66395):
confidence improvement accuracy (*) (**) (***)
napi/make_callback n=1000000 type='AsyncResource' ** 6.57 % ±4.56% ±6.07% ±7.91%
napi/make_callback n=1000000 type='Call' -2.91 % ±5.61% ±7.51% ±9.86%
napi/make_callback n=1000000 type='MakeCallback' * 7.47 % ±5.64% ±7.50% ±9.77%
napi/make_callback n=10000000 type='AsyncResource' *** 8.54 % ±3.42% ±4.55% ±5.93%
napi/make_callback n=10000000 type='Call' -1.02 % ±4.35% ±5.79% ±7.54%
napi/make_callback n=10000000 type='MakeCallback' *** 7.30 % ±2.85% ±3.80% ±4.96%
MakeCallback goes from 128.0 to 119.3 ns at n=1e7. test/async-hooks, the async hooks, AsyncLocalStorage, AsyncResource and nextTick tests in test/parallel, and the new addon test pass.
The new field and the chain are the part to look at first, the design was discussed in nodejs/performance#24.
Disclosure: I used Opus 5.5 (Max) as coding assistant
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot
added
c++
Issues and PRs that require attention from people who are familiar with C++.
lib / src
Issues and PRs involving general changes in the lib/ or src/ directories.
needs-ci
PRs that need a full CI run.
labels
Oct 4, 2026
With no async hook and no executionAsyncResource() user, every
InternalCallbackScope pushed and popped the async ids on the stack, only
for executionAsyncId() and triggerAsyncId() to read the top. Swap the
two ids in place instead: they are all that those two and
process.nextTick() read. executionAsyncResource() is the only reader of
the stack: the scopes that skip it form a chain in AsyncHooks, counted
in a new field, kLazyScopes, and JS asks C++ for the innermost one only
while that count is not zero. The checks for a corrupted stack stay.
Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
codecov
Bot
commented
Oct 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 88.15789% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.57%. Comparing base (3e5c8af) to head (21a6ea2).
⚠️ Report is 572 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #66511 +/- ##
==========================================
- Coverage 92.86% 90.57% -2.29%
==========================================
Files 428 797 +369
Lines 195100 278432 +83332
Branches 30147 53510 +23363
==========================================
+ Hits 181175 252200 +71025
- Misses 13597 16582 +2985
- Partials 328 9650 +9322
... and 498 files with indirect coverage changes
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
nigrosimone reacted with eyes emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
executionAsyncResource() asked first inside a native callback, where the
scope skipped the id stack and holds its resource as a Global, and with
a context pushed on the stack above that scope.
Signed-off-by: Nigro Simone <[email protected]>
|
About the Codecov report: 21a6ea2 adds a test for the two gaps that can be covered, the lazy resource held as a Global (an fs callback) and a context pushed on the stack above a lazy scope.
The lines still reported, popAsyncContext() in lib/internal/async_hooks.js and the check in AsyncHooks::pop_async_context(), are the corrupted stack path. test-improper-order and test-emit-*-on-destroyed go through them, but the child process exits from C++ before it writes its coverage.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@mcollina this one is approved since 9 November and has no commit-queue label. Could it go in the commit queue?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Commit Queue failed
This pull request has multiple commits, but no landing policy was selected.
Add
commit-queue-squash
PRs the Commit Queue should land as one squashed commit.
to land it as one commit, or
commit-queue-rebase
PRs the Commit Queue should land as multiple self-contained commits.
to land the commits separately.
The pull request was removed from the Commit Queue and labeled
commit-queue-failed
PRs whose Commit Queue landing failed and need manual intervention before retrying.
. After resolving the failure, remove that label and add
commit-queue
PRs queued for automated landing through the Commit Queue.
to retry.
Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66511
�[36m⠋�[39m Loading data for nodejs/node/pull/66511
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66511
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66511
�[36m⠋�[39m Getting comments from nodejs/node/pull/66511
�[36m⠋�[39m Getting commits from nodejs/node/pull/66511
✔ Done loading data for nodejs/node/pull/66511
----------------------------------- PR info ------------------------------------
Title src: skip the async id stack when nobody sees it (#66511)
Author Nigro Simone <[email protected]> (@nigrosimone)
Branch nigrosimone:lazy-async-ids -> nodejs:main
Labels c++, lib / src, needs-ci, commit-queue
Commits 2
- src: skip the async id stack when nobody sees it
- test: cover the resource lookup of a lazy async scope
Committers 1
- Nigro Simone <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/66511
Reviewed-By: Matteo Collina <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66511
Reviewed-By: Matteo Collina <[email protected]>
--------------------------------------------------------------------------------
ℹ This PR was created on Sun, 04 Oct 2026 14:57:45 GMT
✔ Approvals: 1
✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/66511#pullrequestreview-5828579602
✔ Last GitHub CI successful
ℹ Last Full PR CI on 2026-11-09T15:58:56Z: https://ci.nodejs.org/job/node-test-pull-request/78926/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78926/
�[36m⠙�[39m Querying data for job/node-test-pull-request/78926/
�[36m⠙�[39m Querying API for job/node-test-pull-request/78926/
✔ Build data downloaded
✔ Last Jenkins CI successful
--------------------------------------------------------------------------------
✔ No git cherry-pick in progress
✔ No git am in progress
✔ No git rebase in progress
--------------------------------------------------------------------------------
�[36m⠹�[39m Bringing origin/main up to date...
�[36m⠹�[39m Bringing origin/main up to date...
From https://github.com/nodejs/node
* branch main -> FETCH_HEAD
660c104059..d32f1bd113 main -> origin/main
✔ origin/main is now up-to-date
main is out of sync with origin/main. Mismatched commits:
- 67e81a2c57 stream: run a replaced write() in the flowing pipe
- d32f1bd113 stream: run a replaced write() in the flowing pipe
--------------------------------------------------------------------------------
HEAD is now at d32f1bd113 stream: run a replaced write() in the flowing pipe
✔ Reset to origin/main
�[36m⠸�[39m Downloading patch for 66511
�[36m⠸�[39m Downloading patch for 66511
From https://github.com/nodejs/node
* branch refs/pull/66511/merge -> FETCH_HEAD
✔ Fetched commits as 660c1040592c..21a6ea2ff095
--------------------------------------------------------------------------------
Auto-merging src/env.cc
Auto-merging src/env.h
Auto-merging src/node_internals.h
[main c893b4db47] src: skip the async id stack when nobody sees it
Author: Nigro Simone <[email protected]>
Date: Sun Oct 4 16:54:28 2026 +0200
7 files changed, 144 insertions(+), 5 deletions(-)
create mode 100755 test/addons/async-resource/test-execution-async-resource.js
[main ffe0b8d4c1] test: cover the resource lookup of a lazy async scope
Author: Nigro Simone <[email protected]>
Date: Wed Oct 21 07:50:24 2026 +0200
1 file changed, 27 insertions(+)
create mode 100644 test/parallel/test-async-hooks-execution-async-resource-lazy.js
✔ Patches applied
There are 2 commits in the PR. Attempting autorebase.
(node:765) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
src: skip the async id stack when nobody sees it
With no async hook and no executionAsyncResource() user, every
InternalCallbackScope pushed and popped the async ids on the stack, only
for executionAsyncId() and triggerAsyncId() to read the top. Swap the
two ids in place instead: they are all that those two and
process.nextTick() read. executionAsyncResource() is the only reader of
the stack: the scopes that skip it form a chain in AsyncHooks, counted
in a new field, kLazyScopes, and JS asks C++ for the innermost one only
while that count is not zero. The checks for a corrupted stack stay.
Refs: https://github.com/nodejs/performance/issues/24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/66511
Reviewed-By: Matteo Collina <[email protected]>
--------------------------------------------------------------------------------
[detached HEAD d9d554db84] src: skip the async id stack when nobody sees it
Author: Nigro Simone <[email protected]>
Date: Sun Oct 4 16:54:28 2026 +0200
7 files changed, 144 insertions(+), 5 deletions(-)
create mode 100755 test/addons/async-resource/test-execution-async-resource.js
Rebasing (3/4)
Rebasing (4/4)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
test: cover the resource lookup of a lazy async scope
executionAsyncResource() asked first inside a native callback, where the
scope skipped the id stack and holds its resource as a Global, and with
a context pushed on the stack above that scope.
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/66511
Reviewed-By: Matteo Collina <[email protected]>
--------------------------------------------------------------------------------
[detached HEAD 7f439d546b] test: cover the resource lookup of a lazy async scope
Author: Nigro Simone <[email protected]>
Date: Wed Oct 21 07:50:24 2026 +0200
1 file changed, 27 insertions(+)
create mode 100644 test/parallel/test-async-hooks-execution-async-resource-lazy.js
Successfully rebased and updated refs/heads/main.
--------------------------------------------------------------------------------
ℹ Add `commit-queue-squash` label to land the PR as one commit, or `commit-queue-rebase` to land as separate commits.
View workflow run
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
aduh95
pushed a commit
that referenced
this pull request
Nov 23, 2026
With no async hook and no executionAsyncResource() user, every
InternalCallbackScope pushed and popped the async ids on the stack, only
for executionAsyncId() and triggerAsyncId() to read the top. Swap the
two ids in place instead: they are all that those two and
process.nextTick() read. executionAsyncResource() is the only reader of
the stack: the scopes that skip it form a chain in AsyncHooks, counted
in a new field, kLazyScopes, and JS asks C++ for the innermost one only
while that count is not zero. The checks for a corrupted stack stay.
Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: #66511
Reviewed-By: Matteo Collina <[email protected]>
gabylb
pushed a commit
to gabylb/node
that referenced
this pull request
Nov 27, 2026
With no async hook and no executionAsyncResource() user, every
InternalCallbackScope pushed and popped the async ids on the stack, only
for executionAsyncId() and triggerAsyncId() to read the top. Swap the
two ids in place instead: they are all that those two and
process.nextTick() read. executionAsyncResource() is the only reader of
the stack: the scopes that skip it form a chain in AsyncHooks, counted
in a new field, kLazyScopes, and JS asks C++ for the innermost one only
while that count is not zero. The checks for a corrupted stack stay.
Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: nodejs#66511
Reviewed-By: Matteo Collina <[email protected]>
Reviewers
mcollina
mcollina approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
c++
Issues and PRs that require attention from people who are familiar with C++.
commit-queue-squash
PRs the Commit Queue should land as one squashed commit.
lib / src
Issues and PRs involving general changes in the lib/ or src/ directories.
needs-ci
PRs that need a full CI run.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|