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 BenchmarkFunctionRemover._uses_benchmark_fixture by 75% in PR #313 (skip-benchmark-instrumentation)
Here is a version **optimized for runtime and memory** using several strategies.
- Replace unnecessary `ast.walk` with a manual, less memory-intensive traversal in `_uses_benchmark_fixture` that **short-circuits** as soon as a benchmark call is found, avoiding the creation of all nodes.
- Move frequently accessed properties outside of loops when possible.
- Rearrange if-elif logic in `_is_benchmark_marker` for faster common-case handling.
- Inline simple boolean expressions when they are only used once.
- Eliminate redundant checks and return as soon as a true condition is satisfied.
- Use tuple membership tests for quick attribute string comparisons.
All logic and comments are preserved. Only inner loop memory and checks are optimized.
The main speedup comes from replacing `ast.walk()` (which loads *all* descendant nodes into memory) with a **manual stack-based traversal** that only visits nodes that are necessary and short-circuits (returns) as soon as any match is found. This reduces both runtime and memory usage, especially on large ASTs.
0 commit comments