Skip to content

Conversation

IlyasShabi
Copy link
Contributor

Improve dgram getSendQueueSize and getSendQueueCount performance by using V8 fast API.

Local benchmark:

                                                      confidence improvement accuracy (*)   (**)  (***)
dgram/get-send-queue-info.js method='count' n=5000000        ***    127.63 %       ±1.01% ±1.35% ±1.77%
dgram/get-send-queue-info.js method='size' n=5000000         ***    127.77 %       ±2.18% ±2.92% ±3.86%

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP. needs-ci PRs that need a full CI run. labels Jul 13, 2025
@IlyasShabi IlyasShabi marked this pull request as ready for review July 13, 2025 22:32
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

❌ Patch coverage is 47.82609% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.56%. Comparing base (59b70e5) to head (780bd7e).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/udp_wrap.cc 47.82% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59054      +/-   ##
==========================================
- Coverage   88.56%   88.56%   -0.01%     
==========================================
  Files         704      704              
  Lines      208156   208176      +20     
  Branches    40009    40012       +3     
==========================================
+ Hits       184361   184373      +12     
- Misses      15817    15828      +11     
+ Partials     7978     7975       -3     
Files with missing lines Coverage Δ
src/udp_wrap.h 100.00% <ø> (ø)
src/udp_wrap.cc 76.86% <47.82%> (-1.43%) ⬇️

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

bench.start();

if (method === 'size') {
for (let i = 0; i < n; ++i) server.getSendQueueSize();
Copy link
Member

Choose a reason for hiding this comment

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

I think at some point this will be JIT-eliminated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that getSendQueueSize() will not be JIT eliminated because it still calls into libuv. Im using size and count now to accumulate the results in order to make that explicit

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

nevermind, I was looking to HEAD.

@RafaelGSS RafaelGSS added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 17, 2025
@IlyasShabi IlyasShabi force-pushed the ishabi/get-send-queue-info branch from 0f7af8e to 7f9c6e8 Compare July 21, 2025 11:11
@IlyasShabi IlyasShabi added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 21, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 21, 2025
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/59054
✔  Done loading data for nodejs/node/pull/59054
----------------------------------- PR info ------------------------------------
Title      dgram: improve get-send-queue-info performance (#59054)
Author     Ilyas Shabi <[email protected]> (@IlyasShabi)
Branch     IlyasShabi:ishabi/get-send-queue-info -> nodejs:main
Labels     dgram, c++, author ready, needs-ci
Commits    3
 - dgram: improve get-send-queue-info performance
 - keep packets unsent to have data in getters
 - fix benchmark test
Committers 1
 - ishabi <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/59054
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/59054
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sun, 13 Jul 2025 22:32:01 GMT
   ✔  Approvals: 2
   ✔  - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/59054#pullrequestreview-3031186521
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/59054#pullrequestreview-3038885029
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2025-07-17T21:21:09Z: https://ci.nodejs.org/job/node-test-pull-request/67989/
   ⚠  Commits were pushed after the last Full PR CI run:
   ⚠  - dgram: improve get-send-queue-info performance
   ⚠  - keep packets unsent to have data in getters
   ⚠  - fix benchmark test
- Querying data for job/node-test-pull-request/67989/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/16423922247

@IlyasShabi IlyasShabi force-pushed the ishabi/get-send-queue-info branch from 7f9c6e8 to 0d00b58 Compare July 28, 2025 09:14
@IlyasShabi IlyasShabi requested review from RafaelGSS and jasnell July 29, 2025 08:44
Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

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

I think it would be safer to test on fastApi as well, would you mind adding a test for it? You can use this one as example: https://github.com/nodejs/node/blob/cd0c5159e64353bc057c5704767145b46887c735/test/parallel/test-os-fast.js

Just a little reminder, you need to wrap your function during the test (testFastOs in the example above) to pass that function to the v8 optimize, it fails if you try to optimize your new method directly.

@H4ad H4ad removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jul 29, 2025
@H4ad
Copy link
Member

H4ad commented Jul 29, 2025

You also need to update the first commit message to reflect the new change: add fast api for get-send-queue-size method

@H4ad H4ad added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Jul 29, 2025
@IlyasShabi IlyasShabi force-pushed the ishabi/get-send-queue-info branch from 0d00b58 to b249db8 Compare August 4, 2025 11:16
@IlyasShabi IlyasShabi requested a review from a team as a code owner October 13, 2025 20:10
@IlyasShabi IlyasShabi marked this pull request as draft October 13, 2025 20:10
@IlyasShabi IlyasShabi force-pushed the ishabi/get-send-queue-info branch from 54fbffa to 780bd7e Compare October 13, 2025 20:14
@IlyasShabi IlyasShabi marked this pull request as ready for review October 13, 2025 20:14
@aduh95
Copy link
Contributor

aduh95 commented Oct 13, 2025

Benchmark CI: https://github.com/aduh95/node/actions/runs/18478104954
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1741/

                                                                     confidence improvement accuracy (*)    (**)   (***)
dgram/get-send-queue-info.js method='count' n=5000000                       ***     33.55 %       ±6.16%  ±8.13% ±10.44%
dgram/get-send-queue-info.js method='size' n=5000000                        ***     34.50 %       ±6.13%  ±8.08% ±10.37%

@anonrig
Copy link
Member

anonrig commented Oct 13, 2025

good work

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 14, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 14, 2025
@nodejs-github-bot
Copy link
Collaborator

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. dgram Issues and PRs related to the dgram subsystem / UDP. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants