-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 performance of looks_like_numpy_member()
#2178
Improve performance of looks_like_numpy_member()
#2178
Conversation
Avoids 32% of the calls to isinstance() when linting astroid
for more information, see https://pre-commit.ci
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2178 +/- ##
==========================================
- Coverage 92.60% 92.60% -0.01%
==========================================
Files 94 94
Lines 10800 10798 -2
==========================================
- Hits 10001 9999 -2
Misses 799 799
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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'm wondering if we should treat numpy this way at all ? Could we create a pylint-numpy plugin that would be the only one doing the check ?
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.
Funny, I have local branch that fixes this exact issue.
Another improvement could be not to create a brain per method, but just pass a set of member names and see if the attribute name is in it. There is no need to have a separate brain for every possible member.
Do agree with Pierre though that ideally this should be moved out of the base astroid package.
Not sure if you followed that @jacobtylerwalls but we created a proof of concept "pylint-tensorflow" project to see if brains could be moved (tensorflow is heavy). Right now it's not in working condition, but if loading brains make astroid load slow, extending such plugins -- once we're clear about how they would work exactly -- would be within reach. Right now the idea would be to make user install the plugin if they use tensorflow, numpy, etc... Like they already do for django for example. |
Sounds good. Let's do both. Let's improve this code and then when it's extracted into a plugin it's also improved code over there.
Thought of this also; shouldn't be hard to do this on the same branch. |
Oh, whoops, I'm unvolunteering for this part, as it's hairier than I anticipated. The method names correspond to specific function transforms. I think I'm going to take the W here and merge what's here. Thanks for the reviews! |
Type of Changes
Description
This method is the hottest path in astroid by number of primitive calls(!) Every name and attribute goes through it, multiplied by the number of numpy method names we compare against.
We already know whether we have a
Name
orAttribute
when registering the transform, so avoiding re-checking the type here saves 32% of the calls toisinstance()
when linting the entire astroid package.Benchmark
for
pylint astroid
on my M1 mac running python 3.11.2, a savings of 0.4s out of 16.7s, or about 2.5% wall time:main
PR