-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Reduce calls to item.ihook #7397
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
Conversation
06031ab
to
8cd346f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would a better patch be to attach ihook
directly instead of lazily? I'm not sure assigning a local variable for an attribute access is obvious / idiomatic enough and will likely regress
8cd346f
to
84b9762
Compare
I agree, making |
84b9762
to
a1a069b
Compare
Thanks for looking at this @lgeiger. I prefer to avoid a cache in complex cases like this because it likely increases memory usage (didn't measure), and possibly has cache invalidation issues, and the gain is not big. Preferably we make it not slow in the first place. At least we should know what makes it slow exactly... So I prefer the initial version, which is a clear improvement. |
I do wonder if a lru cache for the fsproxies would be a good path for this there can be thousands of tests per file, so creating a instance per item when it's per path seems excessive |
a1a069b
to
84b9762
Compare
Thanks for the comments! I reverted to the original version and will take another look at it next week. |
84b9762
to
97d2c71
Compare
In Looking at the implementation, it seems a bit costly indeed to be done all the time, so a good candidate for caching: Lines 546 to 560 in 1ae4182
But Given that it is not that simple, I think we can go forward with this PR and think of a better solution later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer we don't cache this; it calls _getconftestmodules
(which is cached itself) which imports stuff and whatnot, it depends on config
and _conftest_plugins
which can conceivable mutate, and it has a not-perfectly-clear inheritance structure, so it seems too dangerous. And the benefits are not great. I think we should look into optimizing the function itself, instead.
The current version is a simple win however, so 👍 on that.
When scrolling through #7338 I noticed that the
item.ihook
property is called fairly often. There are two place where this access can be cached with trivial changes. When runningempty.py
calls to ihook are reduced from 14039 to 13039. While this doesn't result in significant performance gains I think it might still be useful to include since it doesn't increase code complexity.