GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: do not shrink async resources on every pop by nigrosimone · Pull Request #66344 · nodejs/node

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Sep 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

AsyncHooks::pop_async_context() calls shrink_to_fit() on native_execution_async_resources_ after every pop. With the MSVC and libc++ standard libraries, shrink_to_fit() on an empty std::deque frees its storage, so every top-level callback scope allocates it again on push and frees it on pop. libstdc++ does nothing here, so on Linux nothing change.

Now the deque keeps its storage, like the async_ids_stack_ next to it, which never shrinks.

Until v24 the shrink ran only when the size was over 16 and under half of the capacity, so only after a deep nesting. Since #56457 it runs on every pop.

The same pattern in a small program, on Window with MSVC: 136-147 ns per callback with shrink_to_fit(), 6 ns without. macOS uses libc++, which frees the empty deque in the same way (not measured).

#include <chrono>
#include <cstdio>
#include <deque>
#include <variant>

std::deque<std::variant<int*, long*>> resources;
int value;

// Same as push_async_context() and pop_async_context() at depth 0.
__declspec(noinline) void Push() { resources.resize(1); resources[0] = &value; }
__declspec(noinline) void Pop() { resources.resize(0); resources.shrink_to_fit(); }

int main() {
  const int n = 5000000;
  auto start = std::chrono::steady_clock::now();
  for (int i = 0; i < n; i++) { Push(); Pop(); }
  auto end = std::chrono::steady_clock::now();
  printf("%.1f ns\n", std::chrono::duration<double, std::nano>(end - start).count() / n);
}

Refs: #66316
Refs: 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.

ShenHongFei reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

  • the guide for first-time contributors
  • the contribution and automation policies
  • the pull request guide
  • the AI use policy
  • the Code of Conduct

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nigrosimone
nigrosimone marked this pull request as ready for review September 29, 2026 07:06
@codecov

codecov Bot commented Sep 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (3e5c8af) to head (a979326).
⚠️ Report is 409 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66344      +/-   ##
==========================================
- Coverage   92.86%   90.50%   -2.36%     
==========================================
  Files         428      797     +369     
  Lines      195100   278361   +83261     
  Branches    30147    53500   +23353     
==========================================
+ Hits       181175   251936   +70761     
- Misses      13597    16809    +3212     
- Partials      328     9616    +9288     
Files with missing lines Coverage Δ
src/env.cc 84.42% <ø> (ø)

... and 501 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nigrosimone nigrosimone mentioned this pull request Sep 29, 2026
MakeCallback is very slow nodejs/performance#24
Open
anonrig
anonrig approved these changes Oct 4, 2026
View reviewed changes
@anonrig anonrig added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 4, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 4, 2026
@nodejs-github-bot

nodejs-github-bot commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78166/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@panva panva added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Oct 5, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Oct 5, 2026
@nodejs-github-bot

nodejs-github-bot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78180/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nigrosimone nigrosimone mentioned this pull request Oct 11, 2026
src: keep ALS store in AsyncResource::MakeCallback #66326
Merged
@nigrosimone

nigrosimone commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@anonrig CI is green and this has your approval for more than 7 days, could you add commit-queue?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gurgunday
gurgunday approved these changes Oct 16, 2026
View reviewed changes

@gurgunday gurgunday left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

I like this change, however this means on Windows it will never shrink

I am still approving because async_ids_stack_, sitting right next to it, already keeps 16 bytes per level forever, on every platform, so we're already making similar tradeoffs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nigrosimone reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@nigrosimone
src: do not shrink async resources on every pop
a979326
AsyncHooks::pop_async_context() calls shrink_to_fit() on
native_execution_async_resources_ after every pop. With the MSVC and
libc++ standard libraries, shrink_to_fit() on an empty std::deque frees
its storage, so every top-level callback scope allocates it again on
push and frees it on pop. libstdc++ does nothing here.

A program with the same pattern, a std::deque of the same variant going
from 0 to 1 to 0 elements, takes 136-147 ns per callback on Windows
with MSVC, and 6 ns without shrink_to_fit(). The async_ids_stack_ next
to it never shrinks either.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
@nigrosimone
nigrosimone force-pushed the async-resources-no-shrink branch from a3a1b3c to a979326 Compare October 20, 2026 17:54
@nigrosimone

nigrosimone commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main after #66395 landed, it touched the same lines in pop_async_context(). The change is still only the shrink_to_fit() line.

@anonrig @gurgunday could one of you start a CI and add commit-queue?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@inoway46 inoway46 added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 2, 2026
@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 9, 2026
mcollina
mcollina approved these changes Nov 9, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 9, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 9, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78927/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gurgunday
gurgunday approved these changes Nov 9, 2026
View reviewed changes
@gurgunday gurgunday added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 9, 2026
@gurgunday gurgunday mentioned this pull request Nov 9, 2026
src: stop shrinking async resource stack on pop #67362
Closed
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 9, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78937/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sxa sxa mentioned this pull request Nov 10, 2026
test-perf-hooks-histogram-external-memory failures on node-test-comit-plinux #67374
Closed
@mcollina mcollina added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 17, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 2231574 into nodejs:main Nov 17, 2026
76 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Landed in 2231574

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 17, 2026
aduh95 pushed a commit that referenced this pull request Nov 19, 2026
@nigrosimone @aduh95
src: do not shrink async resources on every pop
9550562
AsyncHooks::pop_async_context() calls shrink_to_fit() on
native_execution_async_resources_ after every pop. With the MSVC and
libc++ standard libraries, shrink_to_fit() on an empty std::deque frees
its storage, so every top-level callback scope allocates it again on
push and frees it on pop. libstdc++ does nothing here.

A program with the same pattern, a std::deque of the same variant going
from 0 to 1 to 0 elements, takes 136-147 ns per callback on Windows
with MSVC, and 6 ns without shrink_to_fit(). The async_ids_stack_ next
to it never shrinks either.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: #66344
Refs: #66316
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2026-11-25, Version 27.0.0-alpha.0.2.0 (Alpha) #67757
Merged
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@nigrosimone @gabylb
src: do not shrink async resources on every pop
86a0e41
AsyncHooks::pop_async_context() calls shrink_to_fit() on
native_execution_async_resources_ after every pop. With the MSVC and
libc++ standard libraries, shrink_to_fit() on an empty std::deque frees
its storage, so every top-level callback scope allocates it again on
push and frees it on pop. libstdc++ does nothing here.

A program with the same pattern, a std::deque of the same variant going
from 0 to 1 to 0 elements, takes 136-147 ns per callback on Windows
with MSVC, and 6 ns without shrink_to_fit(). The async_ids_stack_ next
to it never shrinks either.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: nodejs#66344
Refs: nodejs#66316
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@anonrig anonrig anonrig approved these changes
@gurgunday gurgunday gurgunday approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

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.

8 participants

@nigrosimone @nodejs-github-bot @mcollina @anonrig @gurgunday @panva @ronag @inoway46
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.