Commit 583a03a
authored
⚡️ Speed up method
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.ImportAnalyzer.visit_ImportFrom by 240% in PR #355 (filter_test_files_by_imports_bug_fix)1 parent 66c75a4 commit 583a03a
1 file changed
+40
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
| |||
181 | 190 | | |
182 | 191 | | |
183 | 192 | | |
184 | | - | |
| 193 | + | |
| 194 | + | |
185 | 195 | | |
186 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
187 | 200 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
193 | 205 | | |
194 | | - | |
195 | | - | |
196 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
197 | 212 | | |
198 | | - | |
199 | | - | |
| 213 | + | |
200 | 214 | | |
201 | | - | |
| 215 | + | |
| 216 | + | |
202 | 217 | | |
203 | | - | |
204 | | - | |
205 | | - | |
| 218 | + | |
206 | 219 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 220 | + | |
210 | 221 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
218 | 235 | | |
219 | 236 | | |
220 | 237 | | |
| |||
0 commit comments