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

Improve subset hook caller & related changes #348

Merged
merged 3 commits into from
Jan 15, 2022

Conversation

bluetech
Copy link
Member

This PR contains 3 changes, which are (mostly) conceptually independent but better understood together.

The second commit fixes #346 and #347. The idea is, instead of creating a full-fledged HookCaller, create one which just proxies to the real HookCaller + the plugin filtering. The implementation is a bit hacky but the best I could come up after trying several approaches.

I ran the pytest testsuite and everything passes (after pytest-dev/pytest#9512).

pluggy's benchmark suite looks good (not much difference, maybe a slight improvement). I still need to check pytest though, as pluggy's benchmark doesn't cover subset_hook_caller at all.

Please see the commits for details.

@bluetech
Copy link
Member Author

I'll look into the missing coverage later.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creative approach, i like it as a nice intermediate

@@ -453,6 +451,53 @@ def _maybe_apply_history(self, method: "HookImpl") -> None:
result_callback(res[0])


class _SubsetHookCaller(_HookCaller):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a follow-up we might want to introduce a hook caller protocol as part of the exposed type cleanup

at a later point in time i would like to make pluggy able to work with a dependency topology of plugins
(to better serparae conftests and eventually allow a dependency tree of plugins)

but thats for 2023 or later

testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
testing/test_pluginmanager.py Outdated Show resolved Hide resolved
The hookexec receives them in a single list (which is good), so make the
HookCaller keep them in a single array as well, so can avoid the list
concatenation in the hot call path.

This makes adding a hookimpl a little slower, but not by much, and it is
much colder than calling so the tradeoff makes sense. It is possible to
optimize by keeping track of the splitpoint instead of calculating it
every time, but I don't think it's worth it.
We can do everything necessary with just the `_name2plugin` dict; while
it makes some operations slower (registration and unregistration), they
are not in any hot path (calling) so not a problem.
@bluetech
Copy link
Member Author

I increased the coverage some (and fixed a bug - pm.get_hookcallers() now returns None for an unregistered plugin, as before).

I also tested performance with pytest. Admittedly not very extensively (we really need a proper pytest benchmark) but I checked pytest itself, pandas and some small projects, and not much affect, just a very slight improvement. So I think it's good to go.

@bluetech bluetech merged commit 2304a0f into pytest-dev:main Jan 15, 2022
@bluetech
Copy link
Member Author

Note: I forgot about changelogs. At this point I'll probably add them before the next release.

@bluetech bluetech deleted the subset-caller-6 branch June 12, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PluginManager.subset_hook_caller can cause high memory usage
3 participants