-
Notifications
You must be signed in to change notification settings - Fork 22
Behavior Test Instrumentation to account for input mutation #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍(Review updated until commit ffff5f1)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to ffff5f1
Previous suggestionsSuggestions up to commit b91b61f
|
|
Codeflash Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Persistent review updated to latest commit ffff5f1 |
The optimized code achieves a **22% speedup** through two main optimizations that reduce overhead in AST traversal and attribute lookups: **1. Custom AST traversal replaces expensive `ast.walk()`** The original code uses `ast.walk()` which creates recursive stack frames for every AST node. The optimized version implements `iter_ast_calls()` - a manual iterative traversal that only visits `ast.Call` nodes using a single stack. This eliminates Python's recursion overhead and reduces the O(N) stack frame creation to a single stack operation. **2. Reduced attribute lookups in hot paths** - In `node_in_call_position()`: Uses `getattr()` with defaults to cache node attributes (`node_lineno`, `node_end_lineno`, etc.) instead of repeated `hasattr()` + attribute access - In `find_and_update_line_node()`: Hoists frequently-accessed object attributes (`fn_obj.qualified_name`, `self.mode`, etc.) to local variables before the loop - Pre-creates reusable AST nodes (`codeflash_loop_index`, `codeflash_cur`, `codeflash_con`) instead of recreating them in each iteration **Performance characteristics:** - **Small AST trees** (basic function calls): 5-28% faster due to reduced attribute lookups - **Large AST trees** (deeply nested calls): 18-26% faster due to more efficient traversal avoiding `ast.walk()` - **Large call position lists**: 26% faster due to optimized position checking with cached attributes The optimizations are most effective for complex test instrumentation scenarios with large AST trees or many call positions to check, which is typical in code analysis and transformation workflows.
⚡️ Codeflash found optimizations for this PR📄 22% (0.22x) speedup for
|
…25-11-01T00.02.02 ⚡️ Speed up method `InjectPerfOnly.find_and_update_line_node` by 22% in PR #867 (`inspect-signature-issue`)
|
This PR is now faster! 🚀 @misrasaurabh1 accepted my optimizations from: |
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
|
This PR is now faster! 🚀 Aseem Saxena accepted my code suggestion above. |
PR Type
Enhancement, Tests
Description
Bind call args via inspect.signature
Apply defaults to bound arguments
Route args/kwargs through wrapper in behavior mode
Add inspect import for instrumentation
Diagram Walkthrough
File Walkthrough
instrument_existing_tests.py
Bind call args and pass via wrappercodeflash/code_utils/instrument_existing_tests.py
FunctionCallNodeArguments.inspectfor new binding logic.