Skip to content

Keep the Environment in AsyncResource and pass it to node::MakeCallback - #1027

Draft
nigrosimone wants to merge 1 commit into
nodejs:mainfrom
nigrosimone:makecallback-env
Draft

nigrosimone wants to merge 1 commit into
nodejs:mainfrom
nigrosimone:makecallback-env

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Nan::AsyncResource::runInAsyncScope() calls node::MakeCallback(isolate, ...), and Node looks up the Environment from the callback on every call. nodejs/node#66510 adds an overload that takes the Environment, so the resource takes it once in the constructor and passes it. This is also the path of Nan::Callback::Call() with a resource, so Nan::AsyncWorker callbacks get it too. In the benchmark of that PR it is 133 -> 119 ns per call.

The variants with a method name or a symbol still call Node as before.

Draft until nodejs/node#66510 ships in a release: the NODE_MAJOR_VERSION >= 27 guard is a placeholder, I will set the first version that has the overload. Older versions keep the current call. Checked that it compiles with the headers of v26.13.1 (old path) and of the 2026-11-27 nightly (new path).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant