Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nnop opened this issue May 29, 2019 · 3 comments
Open

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

nnop opened this issue May 29, 2019 · 3 comments

Comments

@nnop
Copy link

nnop commented May 29, 2019

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

@nnop nnop 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? May 29, 2019
@goodboy
Copy link
Contributor

goodboy commented May 29, 2019

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!

@RonnyPfannschmidt
Copy link
Member

@goodboy PYTEST_DEBUG uses tracing to sort out the call tree

@goodboy
Copy link
Contributor

goodboy commented May 29, 2019

@RonnyPfannschmidt gotcha, thanks.

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

No branches or pull requests

3 participants