GeezerVison is showing github.com — MakeCallback is very slow · Issue #24 · nodejs/performance
MakeCallback is very slow #24DescriptionCalling into JS from CPP is very slow. Is this due to async hooks? Could we disable that with a global option if the user doesn't need async hooks? Activityjoyeecheung commented on Nov 21, 2022 See past discussions nodejs/node#10101 - I think the conclusion was that it wasn't that slow, but that was measured 6 years ago and before V8 rolled out several architectural redesigns. We have also deprecated domains for a long time. Maybe the situations have changed now. Would be good to have some new measurements to see if it is worth a shot making it some kind of optional thing. anonrig commented on Nov 21, 2022
Could we disable that with a global option if the user doesn't need async hooks?
Can you explain this in detail? I'm trying to understand the current implementation, and a quick explanation could/would save a lot of time :) ronag commented on Nov 22, 2022
Could we disable that with a global option if the user doesn't need async hooks?
Can you explain this in detail? I'm trying to understand the current implementation, and a quick explanation could/would save a lot of time :)
I don't know much about the details. Async hooks are used to propagate async context. It has a constant overhead even if you don't use it. mcollina commented on Nov 22, 2022 SponsorMember More actions async_hooks have a tiny overhead if disabled and a significant overhead if enabled. ronag commented on Nov 22, 2022
async_hooks have a tiny overhead if disabled and a significant overhead if enabled.
Is it possible to disable it? mcollina commented on Nov 22, 2022 SponsorMember More actions Not really. That's described in the linked issue. Maybe a compile-time flag could do it but we are talking ns of difference. abenhamdine commented on Dec 1, 2022 benjamingr commented on May 23, 2023 Interesting stuff (though bad manners) at uNetworking/uWebSockets.js#904 namely that experiment (that does break async_hooks but also improves performance) H4ad commented on Jul 11, 2023 I could be wrong, but once this nodejs/node#48528 is merged, we can probably rewrite MakeCallback to use AsyncContextFrame, right? Assuming AsyncContextFrame is faster than async_hooks. benjamingr commented on Jul 12, 2023 @H4ad that would work for people using AsyncLocalStorage but not for people otherwise using async hooks Reacted by Vinicius Lourenço Qard commented on Oct 2, 2023 I've been wanting to split all the async_hooks stuff in C++ out into a delegate class which we could use a no-op version for until a hook is registered. That would make it easier to at least contain the overhead when it's not in-use. Reacted by Matteo Collina, Robert Nagy and Vinicius Lourenço joyeecheung commented on Oct 19, 2023 My understanding (or, from nodejs/node#10101) is that async hooks do not actually contribute much to the overhead when it's not enabled - and it's opt-in already so users would be willingly taking the hit. Most of the overhead comes from the tick callback for process.nextTick. While it also only incurs a lot of overhead when actually used, due to the prevalence of its usage in Node.js internals and the user land, the overhead is also much more prevalent. Doing something about async hooks helps a bit, but it's also only a very small piece of the puzzle because it's actually not used that much in the user land. process.nextTick() is the real beast here that affect almost all use cases. nigrosimone commented on Nov 26, 2026 Update: all the PRs landed!
Reacted by Vinicius Lourenço nigrosimone commented on Nov 27, 2026 Before and after the whole series, measured with the official nightly binaries: v27.0.0-nightly20260928 (before nodejs/node#66316) and v28.0.0-nightly20261126 (after all the PRs except nodejs/node#66510). benchmark/napi/make_callback built for each, 30 alternated runs on one core, Linux x64 (WSL2), n=1e7:
The part of MakeCallback that is Node goes from about 138 to about 61 ns. nodejs/node#66510 is opt-in and adds its own 133 -> 119 ns for addons that use it.
Thanks to everyone who reviewed. ❤️ Reacted by Arnaud Benhamdine, Matteo Collina, Robert Nagy and Vinicius Lourenço mcollina commented on Nov 27, 2026 SponsorMember More actions Are there any places in Node where an environment can be cached and the new makecallback taking an environment could be used? Reacted by Nigro Simone Reacted by Nigro Simone nigrosimone commented on Nov 27, 2026 Yes! I found three places. Two are changed in nodejs/node#67833: AsyncResource::MakeCallback(), the path of the addons that use node::AsyncResource, and CheckImmediate(). The third is the TLS ticket key callback, a rare path, so I left it. For NAN, which calls node::MakeCallback() directly, there is a draft in nodejs/nan#1027.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|