Skip to content

Conversation

@gurgunday
Copy link
Member

Does the same optimization as #59873 for queueMicrotask

branch:

./node benchmark/run.js --filter queue-microtask process

process/queue-microtask-breadth.js
process/queue-microtask-breadth.js n=400000: 18,938,347.488090977

process/queue-microtask-depth.js
process/queue-microtask-depth.js n=1200000: 35,862,646.06556887

main

./node benchmark/run.js --filter queue-microtask process

process/queue-microtask-breadth.js
process/queue-microtask-breadth.js n=400000: 5,198,220.087856157

process/queue-microtask-depth.js
process/queue-microtask-depth.js n=1200000: 12,707,696.847598467

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels Nov 30, 2025
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Nov 30, 2025
@gurgunday gurgunday force-pushed the feat/optimize-enqueue branch from ae950e3 to a6615a8 Compare November 30, 2025 20:20
@gurgunday gurgunday changed the title process: stream: preserve AsyncLocalStorage on queueMicrotask only when needed process: preserve AsyncLocalStorage on queueMicrotask only when needed Nov 30, 2025
@gurgunday gurgunday force-pushed the feat/optimize-enqueue branch from a6615a8 to 2f8776e Compare November 30, 2025 20:27
@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.58%. Comparing base (6274eb7) to head (2f8776e).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60913      +/-   ##
==========================================
+ Coverage   88.55%   88.58%   +0.02%     
==========================================
  Files         703      703              
  Lines      208291   208296       +5     
  Branches    40170    40166       -4     
==========================================
+ Hits       184443   184509      +66     
+ Misses      15874    15807      -67     
- Partials     7974     7980       +6     
Files with missing lines Coverage Δ
lib/internal/process/task_queues.js 100.00% <100.00%> (ø)

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

@Flarna Flarna added the async_local_storage AsyncLocalStorage label Dec 1, 2025
@gurgunday
Copy link
Member Author

cc @nodejs/performance

WDYT?

@H4ad H4ad added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 6, 2025
@H4ad
Copy link
Member

H4ad commented Dec 6, 2025

Before merging, some concerns raised in another PR with same changes:

One thing worth noting is that this would be a breaking change as currently the AsyncLocalStorage.bind(...) will always bind, even if there are no hooks or stores in use, but async_hooks could start listening at any time. In the current model you could start listening after the bind call there but before the callback is called and you would see the events. After this change you would not.
By @Qard

Would mind giving some thoughts on this one, @mcollina and @Qard?

Edit:
Benchmark: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1770/

@H4ad H4ad added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 6, 2025
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Dec 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2025

Failed to start CI
   ⚠  No approving reviews found
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/19980375054

@H4ad H4ad removed the request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. label Dec 6, 2025
@Qard
Copy link
Member

Qard commented Dec 6, 2025

@H4ad Yes, the same concern applies. It is, in my opinion, problematic that it was ever possible to start seeing events for a given task partway through its lifecycle rather than deciding at emit time if any of the events should be present. But that is certainly a breaking change and so should be marked as such. A desirable change, I think. But a breaking one nonetheless.

At the same time though, async_hooks is still marked as experimental, and AsyncLocalStorage no longer relies on it, so the break is likely a lot less critical. We may be able to allow it without a major bump. I'm not strongly opinionated either way.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina
Copy link
Member

mcollina commented Dec 6, 2025

I'm ok in this being a minor, but I don't think we can backport it to 22.

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

Labels

async_local_storage AsyncLocalStorage needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js. process Issues and PRs related to the process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants