Repository navigation
node-api: find the Environment once - #66509
Open
nigrosimone wants to merge 1 commit into
Open
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
nigrosimone
force-pushed
the
napi-make-callback-env
branch
from
October 21, 2026 00:58
b729030 to
1a639d6
Compare
Member
|
Why still draft? |
nigrosimone
marked this pull request as ready for review
November 9, 2026 15:09
Contributor
Author
|
No reason now. The gain needed #66395 and the V8 checkpoint fast path underneath, both are on main now. Marked ready. |
nigrosimone
force-pushed
the
napi-make-callback-env
branch
from
November 9, 2026 15:26
1a639d6 to
64bedaa
Compare
ronag
approved these changes
Nov 9, 2026
Member
|
CI is red |
nigrosimone
force-pushed
the
napi-make-callback-env
branch
2 times, most recently
from
November 9, 2026 16:39
5bcd171 to
f911f82
Compare
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 <nigro.simone@gmail.com>
nigrosimone
force-pushed
the
napi-make-callback-env
branch
from
November 9, 2026 17:22
f911f82 to
4000c25
Compare
Contributor
Author
|
@mcollina CI is green now. |
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Without an async context,
napi_make_callbackgoes through the publicnode::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 incan_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 addsnapi/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:
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