-
Notifications
You must be signed in to change notification settings - Fork 21
check if a function is async and add to FTO #678
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 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
…17% in PR #678 (`standalone-fto-async`) The optimized code achieves a **16% speedup** through several targeted micro-optimizations that reduce overhead in the tight loops that traverse AST nodes: **Key Optimizations:** 1. **Local Variable Bindings**: Assigns `ast.iter_child_nodes` and the type tuple to local variables, eliminating repeated attribute lookups during iteration. The profiler shows this reduces the per-hit cost of the main loop from 1560.1ns to 1530.6ns. 2. **Restructured Type Checking**: Splits the combined `isinstance(child, object_type) and child.name == object_name` check into separate conditions. This allows early exit after the type check fails and uses `getattr(child, "name", None)` for safer attribute access, reducing the attribute lookup overhead shown in the profiler (from 403.8ns to 308ns per hit). 3. **Optimized Control Flow**: Changes the nested if-statements to `elif` structure, reducing redundant type checks. The `isinstance(child, fn_type_tuple)` check now only runs when needed, improving branch prediction. 4. **Direct Parent Access**: Caches `parents[0]` as `parent0` to avoid repeated list indexing, though this has minimal impact on the overall performance. **Performance Impact by Test Type:** - **Large-scale tests** (500+ functions/classes): Benefit most from reduced per-node overhead in deep traversals - **Basic cases**: See consistent but smaller improvements due to fewer nodes processed - **Edge cases**: Minimal impact since they often involve early returns or empty searches The optimizations are most effective for codebases with complex AST structures where the functions traverse many nodes, making the micro-optimizations compound significantly.
⚡️ Codeflash found optimizations for this PR📄 17% (0.17x) speedup for
|
PR Type
Enhancement, Bug fix, Tests
Description
Add support for async function detection
Remove
has_any_async_functions
usageFix coverage utils empty database return
Update tests for async discovery and code validation
Diagram Walkthrough
File Walkthrough
4 files
Remove unused async detection function
Add AsyncFunctionDef support to lookup functions
Enable async function discovery and flagging
Remove async restriction and support async AST
1 files
Fix empty DB check order and return `CoverageData`
3 files
Add comprehensive async discovery tests
Resolve symlink paths in code context tests
Replace async detection tests with code validation