Commit 72b51c1
authored
Here is an **optimized** version of your code, focusing on the `_get_function_stats` function—the proven performance bottleneck per your line profiing.
### Optimizations Applied
1. **Avoid Building Unneeded Lists**:
- Creating `possible_keys` as a list incurs per-call overhead.
- Instead, directly check both keys in sequence, avoiding the list entirely.
2. **Short-circuit Early Return**:
- Check for the first key (`qualified_name`) and return immediately if found (no need to compute or check the second unless necessary).
3. **String Formatting Optimization**:
- Use f-strings directly in the condition rather than storing/interpolating beforehand.
4. **Comment Retention**:
- All existing and relevant comments are preserved, though your original snippet has no in-method comments.
---
---
### Rationale
- **No lists** or unneeded temporary objects are constructed.
- Uses `.get`, which is faster than `in` + lookup.
- Returns immediately upon match.
---
**This change will reduce total runtime and memory usage significantly in codebases with many calls to `_get_function_stats`.**
Function signatures and return values are unchanged.
1 parent b7258a9 commit 72b51c1
1 file changed
+9
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
0 commit comments