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: add MakeCallback() taking an Environment by nigrosimone · Pull Request #66510 · nodejs/node

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Oct 4, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

node::MakeCallback() looks up the Environment from the creation context of the callback on every call. This adds an overload that takes it: an addon calling into the same Environment many times (uWS calls one handler per request) takes it once with GetCurrentEnvironment() and passes it. The callback must belong to that Environment.

NODE_EXTERN v8::MaybeLocal<v8::Value> MakeCallback(Environment* env,
                                                   v8::Local<v8::Object> recv,
                                                   v8::Local<v8::Function> callback,
                                                   int argc,
                                                   v8::Local<v8::Value>* argv,
                                                   async_context asyncContext);

It uses the internal helper added in #66509. The new benchmark napi/make_callback_env runs both overloads in the same process: 133.0 to 118.9 ns at n=1e7 (+11.8%) and 130.6 to 124.5 ns at n=1e6 (+4.9%), with #66395 and #66500 underneath, Linux x64, one core.

This is new public API, the shape 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.

All reactions
@nodejs-github-bot

nodejs-github-bot commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/node-api
  • @nodejs/performance
All reactions

Sorry, something went wrong.

Uh oh!

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

@nodejs-github-bot 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
@nigrosimone nigrosimone mentioned this pull request Oct 4, 2026
MakeCallback is very slow nodejs/performance#24
Open
@legendecas legendecas added the node-api Issues and PRs related to Node-API. label Oct 9, 2026
@github-project-automation github-project-automation Bot added this to Node-API Team Project Oct 9, 2026
@github-project-automation github-project-automation Bot moved this to Need Triage in Node-API Team Project Oct 9, 2026
@nigrosimone
nigrosimone force-pushed the makecallback-env branch from 310f545 to 77584c5 Compare October 21, 2026 00:58
@ronag

ronag commented Nov 9, 2026

Copy link
Copy Markdown
Member

Why still draft?

All reactions

Sorry, something went wrong.

Uh oh!

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

@nigrosimone

nigrosimone commented Nov 9, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Now is ready

It adds public API, so I wanted the shape agreed first (nodejs/performance#24). It is on top of #66509. If the shape looks fine to you, I'll mark it ready.

All reactions

Sorry, something went wrong.

Uh oh!

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

@nigrosimone
nigrosimone force-pushed the makecallback-env branch from 77584c5 to 7383b33 Compare November 9, 2026 15:27
@ronag
ronag requested review from anonrig, jasnell and mcollina November 9, 2026 15:41
@nigrosimone
nigrosimone force-pushed the makecallback-env branch 3 times, most recently from 0bf95f3 to c07db16 Compare November 9, 2026 17:22
@nigrosimone
src: add MakeCallback() taking an Environment
3278f89
node::MakeCallback() looks up the Environment from the creation context
of the callback on every call. An addon that calls into the same
Environment many times, a server calling one handler per request for
example, can now take it once with GetCurrentEnvironment() and pass it.
The callback must belong to that Environment.

Add a benchmark, napi/make_callback_env, comparing the two overloads.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
@nigrosimone
nigrosimone force-pushed the makecallback-env branch from c07db16 to 3278f89 Compare November 26, 2026 05:39
@nigrosimone
nigrosimone marked this pull request as ready for review November 26, 2026 05:43
This was referenced Nov 26, 2026
[WIP] Call node::MakeCallback with the Environment taken once per thread uNetworking/uWebSockets.js#1362
Draft
[WIP] perf: call node::MakeCallback with the Environment taken once in serve() Moro-JS/engine#4
Draft
mcollina
mcollina approved these changes Nov 26, 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.

nigrosimone reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@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. node-api Issues and PRs related to Node-API. and removed node-api Issues and PRs related to Node-API. labels Nov 26, 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 26, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@codecov

codecov Bot commented Nov 26, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (fa49b13) to head (3278f89).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/api/callback.cc 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66510      +/-   ##
==========================================
- Coverage   92.59%   90.50%   -2.10%     
==========================================
  Files         433      805     +372     
  Lines      200382   285810   +85428     
  Branches    30786    55184   +24398     
==========================================
+ Hits       185553   258681   +73128     
- Misses      14486    17214    +2728     
- Partials      343     9915    +9572     
Files with missing lines Coverage Δ
src/node.h 92.15% <ø> (ø)
src/api/callback.cc 81.25% <0.00%> (ø)

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

jasnell
jasnell approved these changes Nov 26, 2026
View reviewed changes
@mcollina mcollina added commit-queue PRs queued for automated landing through the Commit Queue. semver-minor PRs that contain new features and should be released in the next minor version. labels Nov 26, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 3872251 into nodejs:main Nov 26, 2026
93 checks passed

Uh oh!

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

@nodejs-github-bot

nodejs-github-bot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Landed in 3872251

nigrosimone reacted with hooray emoji
All reactions
  • 🎉 1 reaction

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 26, 2026
@github-project-automation github-project-automation Bot moved this from Need Triage to Done in Node-API Team Project Nov 26, 2026
nigrosimone added a commit to nigrosimone/fulmine.js that referenced this pull request Nov 27, 2026
@nigrosimone
docs: add nodejs/node#66510 to how it is built
7261ffe
Signed-off-by: Nigro Simone <[email protected]>
This was referenced Nov 27, 2026
src: skip the Environment lookup when it is already known #67833
Open
Keep the Environment in AsyncResource and pass it to node::MakeCallback nodejs/nan#1027
Draft
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@nigrosimone @gabylb
src: add MakeCallback() taking an Environment
ca922df
node::MakeCallback() looks up the Environment from the creation context
of the callback on every call. An addon that calls into the same
Environment many times, a server calling one handler per request for
example, can now take it once with GetCurrentEnvironment() and pass it.
The callback must belong to that Environment.

Add a benchmark, napi/make_callback_env, comparing the two overloads.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: nodejs#66510
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[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
@jasnell jasnell jasnell approved these changes
@anonrig anonrig Awaiting requested review from anonrig

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++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. node-api Issues and PRs related to Node-API. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

Node-API Team Project
Status: Done

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.

6 participants

@nigrosimone @nodejs-github-bot @ronag @mcollina @jasnell @legendecas
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.