You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up method ImportAnalyzer.visit_Attribute by 11% in PR #310 (test-filter-cleanup)
Here is an optimized rewrite of your `ImportAnalyzer` class. The main gains are.
- Reduce unnecessary lookups and checks by pre-computing sets when possible.
- Replace repeated attribute/dict/set lookups with local variables.
- Remove harmless redundant code paths.
- Use early returns aggressively to skip processing once a result is found.
- Optimize attribute access codepath for the most common success scenarios.
All comments are preserved, unchanged where the code wasn't modified.
Key points.
- Replaces `self.generic_visit(node)` with `ast.NodeVisitor.generic_visit(self, node)` to save a function attribute lookup.
- Uses local variables for `self.function_names_to_find` and `self.imported_modules` for potentially faster access.
- Narrowed references for speed in the most time-critical branch.
- Kept code easy to read and all logic/return values identical.
- Preserved all comments and docstrings.
0 commit comments