⚡ Bolt: [performance improvement]#115
Conversation
Co-authored-by: tachyon-beep <544926+tachyon-beep@users.noreply.github.com>
|
👋 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. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes iter_calls_in_function_body (a hot-path AST helper in scanner.ast_primitives) by replacing recursive yield from traversal with an explicit stack-based walk to reduce Python call/generator overhead while preserving traversal behavior.
Changes:
- Replaced recursive generator-based AST traversal with an explicit LIFO stack in
iter_calls_in_function_body. - Preserved scope-boundary behavior (do not descend into nested
def/class/lambdabodies; still attribute header expressions to the enclosing function). - Added a
.jules/bolt.mdnote documenting the optimization and the “reverse before pushing” ordering rule.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/wardline/scanner/ast_primitives.py | Implements the stack-based traversal to speed up call enumeration without changing scope-boundary semantics. |
| .jules/bolt.md | Documents the performance learning/action for future hot-path AST work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # ⚡ Bolt Optimization: Replacing `yield from` recursion with an explicit stack | ||
| # avoids Python function call overhead and generator delegation costs on hot-path AST traversal. | ||
| # Impact: ~25% speedup on local benchmark (0.748s -> 0.561s for 10,000 iterations). | ||
| # Reversing child nodes before pushing preserves the exact pre-order evaluation sequence. |
💡 What: Replaced the recursive
yield fromAST traversal initer_calls_in_function_bodywith an explicit stack-based approach.🎯 Why: The previous recursive generator approach incurred considerable Python function call overhead and generator delegation costs, acting as a bottleneck in static analysis hot-paths.
📊 Impact: Provides a ~25% speedup on local benchmarks (from ~0.748s to ~0.561s for 10,000 iterations), lowering CPU time without altering AST evaluation sequences or coverage.
🔬 Measurement: Run a local benchmarking script parsing a complex AST structure before and after the optimization. Output confirmed ~25% execution time reduction. Tests pass indicating full fidelity with previous traversal behavior.
PR created automatically by Jules for task 16801961517172131531 started by @tachyon-beep