⚡ Bolt: prevent unnecessary memory allocation in AST traversal - #132
⚡ Bolt: prevent unnecessary memory allocation in AST traversal#132tachyon-beep wants to merge 1 commit into
Conversation
Replaced eager list materialization (e.g. list(ast.iter_child_nodes(node))) with direct iterable/generator passing in recursive taint scanner functions. This reduces overhead during deep AST walks without sacrificing readability. 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 applies a small performance-oriented cleanup in the taint scanner’s AST traversal helpers by eliminating eager list materialization during recursion. It aligns the helper signatures with how the AST APIs naturally provide child nodes (iterables/iterators), reducing per-node temporary allocations during deep/wide walks.
Changes:
- Replaced
list(ast.iter_child_nodes(node))with directast.iter_child_nodes(node)passing in_collect_return_pathsand_assignment_callee. - Updated traversal helper type hints from
list[ast.AST]toIterable[ast.AST]. - Added a Bolt note documenting the “avoid list materialization in AST traversal” optimization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/wardline/scanner/taint/variable_level.py | Removes eager list allocations during recursive AST walks and updates traversal helper type hints accordingly. |
| .jules/bolt.md | Documents the AST traversal optimization rationale and the preferred pattern for future changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
💡 What: Replaced eager list materialization (e.g.,
list(ast.iter_child_nodes(node))) with direct iterable passing in_collect_return_pathsand_assignment_callee. Updated type hints fromlist[ast.AST]toIterable[ast.AST].🎯 Why: Generating temporary lists for every traversed AST node during deep recursive walks causes redundant memory allocations. Passing iterators directly avoids this unnecessary GC pressure.
📊 Impact: Reduces memory footprint and provides a micro-optimization for deep/wide AST analysis passes.
🔬 Measurement: Verify with
make test. No behavioral changes were introduced (tests pass seamlessly).PR created automatically by Jules for task 610912571090466570 started by @tachyon-beep