Skip to content

src: stop shrinking async resource stack on pop - #67362

Closed
araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:http-callback-perf
Closed

araujogui wants to merge 1 commit into
nodejs:mainfrom
araujogui:http-callback-perf

Conversation

@araujogui

Copy link
Copy Markdown
Member

pop_async_context() called shrink_to_fit() on every pop. The stack is usually empty once a callback returns, so libc++ and MSVC free the deque's storage and the next push allocates it again. That happens several times per HTTP request.

The shrink used to run only when the stack was large and mostly unused. That check was dropped in #56457.

Measured on macOS (Apple M2, libc++). libstdc++ skips the free in this case, so the gain on Linux is likely small.

benchmark/http/simple.js
                                                                                              confidence   improvement   accuracy (*)    (**)   (***)
http/simple.js duration=3 chunkedEnc=0 c=50 chunks=1 len=4 type='bytes' benchmarker='wrk'     ***             +4.44 %   ±2.15%  ±2.92%  ±3.93%
http/simple.js duration=3 chunkedEnc=1 c=50 chunks=1 len=4 type='bytes' benchmarker='wrk'                     +1.39 %   ±1.79%  ±2.44%  ±3.31%
http/simple.js duration=3 chunkedEnc=0 c=50 chunks=4 len=4 type='bytes' benchmarker='wrk'       *             +2.25 %   ±1.93%  ±2.63%  ±3.54%
http/simple.js duration=3 chunkedEnc=1 c=50 chunks=4 len=4 type='bytes' benchmarker='wrk'      **             +2.26 %   ±1.40%  ±1.91%  ±2.57%
http/simple.js duration=3 chunkedEnc=0 c=50 chunks=1 len=1024 type='bytes' benchmarker='wrk'  ***             +2.46 %   ±0.94%  ±1.29%  ±1.75%
http/simple.js duration=3 chunkedEnc=1 c=50 chunks=1 len=1024 type='bytes' benchmarker='wrk'   **             +1.92 %   ±1.39%  ±1.89%  ±2.56%
http/simple.js duration=3 chunkedEnc=0 c=50 chunks=4 len=1024 type='bytes' benchmarker='wrk'  ***             +1.93 %   ±0.80%  ±1.09%  ±1.46%
http/simple.js duration=3 chunkedEnc=1 c=50 chunks=4 len=1024 type='bytes' benchmarker='wrk'  ***             +2.91 %   ±1.19%  ±1.62%  ±2.19%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 8 comparisons, you can thus
expect the following amount of false-positive results:
  0.40 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.08 false positives, when considering a   1% risk acceptance (**, ***),
  0.01 false positives, when considering a 0.1% risk acceptance (***)

Refs: #56457

pop_async_context() called shrink_to_fit() on every pop. The stack is
usually empty once a callback returns, so libc++ and MSVC free the
deque's storage and the next push allocates it again, several times
per HTTP request.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@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 Nov 9, 2026
@araujogui araujogui added the performance Issues and PRs related to the performance of Node.js. label Nov 9, 2026

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI it's a duplicate of #66344

@araujogui

Copy link
Copy Markdown
Member Author

FYI it's a duplicate of #66344

ty I hadn't seen that PR, closing this as duplicate.

@araujogui araujogui closed this Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.74%. Comparing base (97aed16) to head (8aa938a).
⚠️ Report is 109 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67362      +/-   ##
==========================================
+ Coverage   90.67%   90.74%   +0.06%     
==========================================
  Files         797      798       +1     
  Lines      278773   280016    +1243     
  Branches    53607    53857     +250     
==========================================
+ Hits       252778   254092    +1314     
+ Misses      16356    16219     -137     
- Partials     9639     9705      +66     
Files with missing lines Coverage Δ
src/env.cc 84.36% <ø> (-0.02%) ⬇️

... and 107 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants