Skip to content

⚡ Bolt: prevent unnecessary memory allocation in AST traversal - #132

Open
tachyon-beep wants to merge 1 commit into
mainfrom
bolt/optimize-ast-traversal-allocations-610912571090466570
Open

⚡ Bolt: prevent unnecessary memory allocation in AST traversal#132
tachyon-beep wants to merge 1 commit into
mainfrom
bolt/optimize-ast-traversal-allocations-610912571090466570

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

💡 What: Replaced eager list materialization (e.g., list(ast.iter_child_nodes(node))) with direct iterable passing in _collect_return_paths and _assignment_callee. Updated type hints from list[ast.AST] to Iterable[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

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>
@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.

Copilot AI review requested due to automatic review settings August 2, 2026 16:13

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 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 direct ast.iter_child_nodes(node) passing in _collect_return_paths and _assignment_callee.
  • Updated traversal helper type hints from list[ast.AST] to Iterable[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.

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