⚡ Bolt: [performance improvement] Optimize AST parsing using NodeVisitor#78
⚡ Bolt: [performance improvement] Optimize AST parsing using NodeVisitor#78ishaanxgupta wants to merge 1 commit intomainfrom
Conversation
- Replace `ast.walk` nested loops with `ast.NodeVisitor` in `_extract_calls` - Replace `ast.walk` loops with `ast.NodeVisitor` in `_compute_complexity` and `_extract_imports` - Fix redundant double-counting of inner calls in nested functions - Remove unused variables and imports
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Replaced
ast.walknested loops withast.NodeVisitorimplementations insrc/scanner/ast_parser.py(specifically in_extract_calls,_compute_complexity, and_extract_imports). Cleaned up unused variables and imports.🎯 Why:
The original implementation used
ast.walkrecursively to extract function calls.ast.walktraverses the entire AST subtree without targeted logic, queuing all nodes. When used inside another loop over functions, it leads to O(N²) traversal times. Additionally,ast.walkincurs higher generator overhead thanast.NodeVisitoreven for simpler tasks like computing complexity.📊 Impact:
_extract_calls(from O(N²) to O(N)).🔬 Measurement:
Run profiling or measure execution time on large Python repositories during ingestion. The performance improvement scales linearly with repository size. Tests confirm existing functionality remains identical, minus the scoping bug.
PR created automatically by Jules for task 5995046143637265213 started by @ishaanxgupta