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 InitDecorator.visit_ClassDef by 91% in PR #363 (part-1-windows-fixes)
Here is an optimized version of your program with reduced code execution overhead, memory allocation, and efficient logic. All return values remain exactly the same, and function signatures are unchanged. Comments are preserved as required.
**Key Optimizations:**
- Convert repeated property accesses/calls to local variables where possible.
- Reuse the same decorator AST node object where safe (AST is not mutated elsewhere).
- Pre-check presence of target class and short-circuit early.
- In the loop, short-circuit when `__init__` is found to avoid unnecessary iterations.
**Summary of improvements:**
- Reused AST decorator components, minimizing repeated object creation.
- Early exit on target class and `__init__` findings.
- Less variable assignment and number of iterations.
- All core logic and comments are preserved.
0 commit comments