pluggy icon indicating copy to clipboard operation
pluggy copied to clipboard

How much would the hook wrapping affect the execution time?

Open nnop opened this issue 6 years ago • 3 comments

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 avatar May 29 '19 02:05 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.

@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!

goodboy avatar May 29 '19 04:05 goodboy

@goodboy PYTEST_DEBUG uses tracing to sort out the call tree

RonnyPfannschmidt avatar May 29 '19 06:05 RonnyPfannschmidt

@RonnyPfannschmidt gotcha, thanks.

goodboy avatar May 29 '19 14:05 goodboy