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 — node-api: find the Environment once by nigrosimone · Pull Request #66509 · 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

Without an async context, napi_make_callback goes through the public node::MakeCallback(), which looks up the Environment from the creation context of the callback on every call. The napi_env already knows it, so call into it directly, as the path with an async context does. node_napi_env__::node_env() also looked it up from the context on every call (also in can_call_into_js()): now it is found once, a napi_env lives as long as its Environment.

There was no benchmark for napi_make_callback, so this adds napi/make_callback_napi, a C addon calling it from a libuv timer like an I/O callback.

Alone on 26.3.0 + #66316 the gain is inside the noise (-3.0% and +2.1%, no stars). With #66395 and the V8 checkpoint fast path (#66500) underneath, both now on main, it is +15% (200 to 174 ns), compare.js, 30 runs, Linux x64, one core:

                                     confidence improvement accuracy (*)   (**)  (***)
napi/make_callback_napi n=1000000           ***     15.12 %       ±4.73% ±6.29% ±8.19%
napi/make_callback_napi n=10000000          ***     14.78 %       ±3.82% ±5.10% ±6.68%

The Node-API callback tests and the make-callback addon tests pass. Part of the plan 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
@nigrosimone nigrosimone mentioned this pull request Oct 4, 2026
src: add MakeCallback() taking an Environment #66510
Merged
@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
@nigrosimone
nigrosimone force-pushed the napi-make-callback-env branch from b729030 to 1a639d6 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 marked this pull request as ready for review November 9, 2026 15:09
@nigrosimone

nigrosimone commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

No reason now. The gain needed #66395 and the V8 checkpoint fast path underneath, both are on main now. Marked ready.

All reactions

Sorry, something went wrong.

Uh oh!

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

@nigrosimone
nigrosimone force-pushed the napi-make-callback-env branch from 1a639d6 to 64bedaa Compare November 9, 2026 15:26
ronag
ronag approved these changes Nov 9, 2026
View reviewed changes
@mcollina

mcollina commented Nov 9, 2026

Copy link
Copy Markdown
Member

CI is red

All reactions

Sorry, something went wrong.

Uh oh!

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

@nigrosimone
nigrosimone force-pushed the napi-make-callback-env branch 2 times, most recently from 5bcd171 to f911f82 Compare November 9, 2026 16:39
@ronag ronag 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 9, 2026
@nigrosimone
node-api: find the Environment once
4000c25
Without an async context, napi_make_callback went through the public
node::MakeCallback(), which looks up the Environment from the creation
context of the callback on every call. The napi_env already knows it,
so call into it directly, as the path with an async context does.
node_napi_env__::node_env() also looked it up from the context on every
call: find it once, a napi_env lives as long as its Environment.

Add a benchmark, napi/make_callback_napi.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
@nigrosimone
nigrosimone force-pushed the napi-make-callback-env branch from f911f82 to 4000c25 Compare November 9, 2026 17:22
@nigrosimone

nigrosimone commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@mcollina CI is green now.

All reactions

Sorry, something went wrong.

Uh oh!

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

@codecov

codecov Bot commented Nov 9, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (3e5c8af) to head (4000c25).
⚠️ Report is 637 commits behind head on main.

Files with missing lines Patch % Lines
src/node_api.cc 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66509      +/-   ##
==========================================
- Coverage   92.86%   90.71%   -2.15%     
==========================================
  Files         428      798     +370     
  Lines      195100   280024   +84924     
  Branches    30147    53866   +23719     
==========================================
+ Hits       181175   254025   +72850     
- Misses      13597    16287    +2690     
- Partials      328     9712    +9384     
Files with missing lines Coverage Δ
src/api/callback.cc 80.54% <100.00%> (ø)
src/node_api_internals.h 100.00% <100.00%> (ø)
src/node_internals.h 80.35% <ø> (ø)
src/node_api.cc 77.18% <83.33%> (ø)

... and 545 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 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@legendecas could you take a look from the Node-API side? ronag approved on 9 Nov. The request-ci label is still there, so I think Jenkins CI did not start.

All reactions

Sorry, something went wrong.

Uh oh!

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

mcollina
mcollina approved these changes Nov 25, 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
@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 25, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@ronag ronag added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Nov 25, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 25, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ✖  GitHub CI is still running
   ✖  Last Jenkins CI still running

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66509
�[36m⠋�[39m Loading data for nodejs/node/pull/66509
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66509
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66509
�[36m⠋�[39m Getting comments from nodejs/node/pull/66509
�[36m⠋�[39m Getting commits from nodejs/node/pull/66509
✔  Done loading data for nodejs/node/pull/66509
----------------------------------- PR info ------------------------------------
Title      node-api: find the Environment once (#66509)
Author     Nigro Simone <[email protected]> (@nigrosimone)
Branch     nigrosimone:napi-make-callback-env -> nodejs:main
Labels     c++, lib / src, node-api, needs-ci, commit-queue, commit-queue-squash
Commits    1
 - node-api: find the Environment once
Committers 1
 - Nigro Simone <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/66509
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66509
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sun, 04 Oct 2026 14:57:39 GMT
   ✔  Approvals: 2
   ✔  - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/66509#pullrequestreview-5828345390
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/66509#pullrequestreview-6053647710
   ✖  GitHub CI is still running
   ℹ  Last Full PR CI on 2026-11-25T07:49:09Z: https://ci.nodejs.org/job/node-test-pull-request/79488/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79488/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79488/
�[36m⠙�[39m Querying API for job/node-test-pull-request/79488/
✔  Build data downloaded
   ✖  Last Jenkins CI still running
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

All reactions

Sorry, something went wrong.

Uh oh!

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

legendecas
legendecas approved these changes Nov 25, 2026
View reviewed changes
@legendecas legendecas added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Nov 25, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 72bf392 into nodejs:main Nov 25, 2026
72 checks passed

Uh oh!

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

@nodejs-github-bot

nodejs-github-bot commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Landed in 72bf392

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 25, 2026
@github-project-automation github-project-automation Bot moved this from Need Triage to Done in Node-API Team Project Nov 25, 2026
nigrosimone added a commit to nigrosimone/fulmine.js that referenced this pull request Nov 26, 2026
@nigrosimone
docs: add nodejs/node#66509 to how it is built
c5aa7c3
Signed-off-by: Nigro Simone <[email protected]>
@nigrosimone nigrosimone mentioned this pull request Nov 27, 2026
src: skip the Environment lookup when it is already known #67833
Open
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@nigrosimone @gabylb
node-api: find the Environment once
56dc51b
Without an async context, napi_make_callback went through the public
node::MakeCallback(), which looks up the Environment from the creation
context of the callback on every call. The napi_env already knows it,
so call into it directly, as the path with an async context does.
node_napi_env__::node_env() also looked it up from the context on every
call: find it once, a napi_env lives as long as its Environment.

Add a benchmark, napi/make_callback_napi.

Refs: nodejs/performance#24
Signed-off-by: Nigro Simone <[email protected]>
PR-URL: nodejs#66509
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[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
@ronag ronag ronag approved these changes
@legendecas legendecas legendecas approved these changes

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++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. 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.

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.

5 participants

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