Skip to content

How much would the hook wrapping affect the execution time? #217

Closed as not planned

Description

@nnop

Say my application is a concurrent application and the hook implementation is applied to a great amount of data, which means it would be executed thousands of times.
So, how much is the wrapping work by pluggy affect the execution time?

I red the code and saw there is a relatively long chain from pm.hook.method() calling to the actual implementation.

Below is my summary of the calling chain:

From pm.hook.method which is actually a _HookRelay instance to
-> _HookCaller.__call__
-> PluginManager._hookexec
-> PluginManager._inner_hookexec
-> _multicall in callers.py
-> HookImpl.funcion is the actual hook implmentation

Activity

  1. changed the title [-]How much would the hook wrapping affect the execution time of the hook implementation?[/-] [+]How much would the hook wrapping affect the execution time?[/+] on May 29, 2019
  2. goodboy commented on May 29, 2019

    @goodboy
    Contributor

    Say my application is a concurrent application and the hook implementation is applied to a great amount of data, which means it would be executed thousands of times.

    @nnop this is a very good question and probably a use case we could attempt to optimize for if there was a demonstrable application.

    So, how much is the wrapping work by pluggy affect the execution time?

    I think you've mostly figured out the call stack minus the detail that _multicall of course invokes n hook implementations (depending on what's registered at call time) and any wrappers that intercept each hook call.

    In terms of minimizing the current (what, four?) extra function calls I know I've contemplated removing ._inner_hookexec since it's only used for tracing which I'm not even sure is used that much as a feature (though I'd have to let consumer project maintainers chime in).

    If you want to do some further digging (and we'd appreciate the help) there's a little benchmark test suite that you can play with to try and expose bottlenecks for your use case.

    Hope that helps!

  3. RonnyPfannschmidt commented on May 29, 2019

    @RonnyPfannschmidt
    Member

    @goodboy PYTEST_DEBUG uses tracing to sort out the call tree

  4. goodboy commented on May 29, 2019

    @goodboy
    Contributor

    @RonnyPfannschmidt gotcha, thanks.

  5. RonnyPfannschmidt commented on May 27, 2026

    @RonnyPfannschmidt
    Member

    considering this answered

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions