Skip to content

⚡ Bolt: Remove eager list materialization in AST traversals - #178

Open
tachyon-beep wants to merge 2 commits into
mainfrom
bolt-avoid-eager-ast-materialization-17820923595346048879
Open

⚡ Bolt: Remove eager list materialization in AST traversals#178
tachyon-beep wants to merge 2 commits into
mainfrom
bolt-avoid-eager-ast-materialization-17820923595346048879

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

💡 What: Changed AST traversal functions _assignment_callee, _collect_return_paths, and _find_assignment_callee to accept Iterable[ast.AST] instead of list[ast.AST]. Removed the list() wrapping around ast.iter_child_nodes(node) and func_node.body when passing them to these functions.
🎯 Why: Passing generators directly to recursive traversal functions prevents eager list materialization, eliminating unnecessary memory allocations and improving performance during AST analysis.
📊 Impact: Reduces memory usage and improves speed during deep AST traversals by iterating lazily over child nodes instead of instantiating new lists at every recursion level.
🔬 Measurement: Performance can be verified by profiling memory allocations during large codebase scans.


PR created automatically by Jules for task 17820923595346048879 started by @tachyon-beep

💡 What: Changed AST traversal functions `_assignment_callee`, `_collect_return_paths`, and `_find_assignment_callee` to accept `Iterable[ast.AST]` instead of `list[ast.AST]`. Removed the `list()` wrapping around `ast.iter_child_nodes(node)` and `func_node.body` when passing them to these functions.
🎯 Why: Passing generators directly to recursive traversal functions prevents eager list materialization, eliminating unnecessary memory allocations and improving performance during AST analysis.
📊 Impact: Reduces memory usage and improves speed during deep AST traversals by iterating lazily over child nodes instead of instantiating new lists at every recursion level.
🔬 Measurement: Performance can be verified by profiling memory allocations during large codebase scans.

Co-authored-by: tachyon-beep <544926+tachyon-beep@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 16:33
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes AST traversal in the scanner by switching key recursive helpers to accept Iterable[ast.AST] and by passing child-node iterators and function bodies directly, avoiding repeated list() materialization during deep traversals.

Changes:

  • Updated _assignment_callee and _collect_return_paths in variable_level.py to accept Iterable[ast.AST] and removed eager list() wrapping of func_node.body and ast.iter_child_nodes(...).
  • Updated _find_assignment_callee in flow_trace.py to accept Iterable[ast.AST] and adjusted imports accordingly.
  • Added a Bolt note documenting the performance learning and preferred pattern for AST traversal APIs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/wardline/scanner/taint/variable_level.py Removes eager list materialization in recursive AST return/assignment traversal helpers by using Iterable and passing iterators directly.
src/wardline/scanner/flow_trace.py Broadens _find_assignment_callee’s parameter type to Iterable and updates imports to match.
.jules/bolt.md Documents the “avoid eager list() of AST generators” guidance for future changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

💡 What: Changed AST traversal functions `_assignment_callee`, `_collect_return_paths`, and `_find_assignment_callee` to accept `Iterable[ast.AST]` instead of `list[ast.AST]`. Removed the `list()` wrapping around `ast.iter_child_nodes(node)` and `func_node.body` when passing them to these functions.
🎯 Why: Passing generators directly to recursive traversal functions prevents eager list materialization, eliminating unnecessary memory allocations and improving performance during AST analysis.
📊 Impact: Reduces memory usage and improves speed during deep AST traversals by iterating lazily over child nodes instead of instantiating new lists at every recursion level.
🔬 Measurement: Performance can be verified by profiling memory allocations during large codebase scans.

Co-authored-by: tachyon-beep <544926+tachyon-beep@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants