Skip to content

MakeCallback is very slow #24

Open

Description

@ronag

Calling 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?

Activity

  1. joyeecheung commented on Nov 21, 2022

    @joyeecheung
    Member

    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.

  2. anonrig commented on Nov 21, 2022

    @anonrig
    Member

    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 :)

  3. ronag commented on Nov 22, 2022

    @ronag
    MemberAuthor

    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.

  4. mcollina commented on Nov 22, 2022

    @mcollina
    SponsorMember

    async_hooks have a tiny overhead if disabled and a significant overhead if enabled.

  5. ronag commented on Nov 22, 2022

    @ronag
    MemberAuthor

    async_hooks have a tiny overhead if disabled and a significant overhead if enabled.

    Is it possible to disable it?

  6. mcollina commented on Nov 22, 2022

    @mcollina
    SponsorMember

    Not really. That's described in the linked issue. Maybe a compile-time flag could do it but we are talking ns of difference.

  7. abenhamdine commented on Dec 1, 2022

    @abenhamdine

    see also previous related work in
    nodejs/node#41331
    nodejs/node#41279
    some big picture datapoints here, related to uWebSockets module : uNetworking/uWebSockets.js#341

  8. benjamingr commented on May 23, 2023

    @benjamingr
    Member

    Interesting stuff (though bad manners) at uNetworking/uWebSockets.js#904 namely that experiment (that does break async_hooks but also improves performance)

  9. H4ad commented on Jul 11, 2023

    @H4ad
    Member

    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.

  10. benjamingr commented on Jul 12, 2023

    @benjamingr
    Member

    @H4ad that would work for people using AsyncLocalStorage but not for people otherwise using async hooks

  11. Qard commented on Oct 2, 2023

    @Qard
    Member

    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.

  12. joyeecheung commented on Oct 19, 2023

    @joyeecheung
    Member

    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.

  13. 34 remaining items

  14. nigrosimone commented on Nov 9, 2026

    @nigrosimone

    Update, one month later. Each PR, what it does and the gain measured in it:

    Landed

    Open

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    benchmark-neededAdd to issues that does not have a benchmarkhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions