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_ImportFrom by 240% in PR #355 (filter_test_files_by_imports_bug_fix)
Here is an optimized version of your program, focusing on the key bottlenecks identified in the profiler.
**Major improvements:**
- **Use set lookup and precomputed data:** To avoid repeated work in `any(...)` calls, we build sets/maps to batch-check function names needing exact and prefix matching.
- **Flatten loop logic:** We reduce string concatenation and duplicate calculation.
- **Short-circuit loop on match:** As soon as a match is found, break out of loops ASAP.
- **Precompute most-used string to minimize per-iteration computation.**
**Summary of changes:**
- We pre-group full match and dotted-prefix match targets.
- We remove two `any()` generator expressions over a set in favor of direct set lookups and for-loops over a prefiltered small candidate list.
- All string concatenations and attribute accesses are done at most once per iteration.
- Early returns are used to short-circuit unnecessary further work.
This should be **significantly faster**, especially when the set of names is large and there are many aliases per import.
0 commit comments