Skip to content

⚡ Bolt: avoid eager list materialization in AST traversals - #138

Open
tachyon-beep wants to merge 1 commit into
mainfrom
bolt/ast-node-generator-perf-1881551180393145932
Open

⚡ Bolt: avoid eager list materialization in AST traversals#138
tachyon-beep wants to merge 1 commit into
mainfrom
bolt/ast-node-generator-perf-1881551180393145932

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

💡 What: Updated recursive AST traversals in _assignment_callee and _collect_return_paths to accept Iterable[ast.AST] and pass ast.iter_child_nodes() directly instead of eagerly materializing it into lists using list().

🎯 Why: Calling list(ast.iter_child_nodes()) allocates a new list in memory at every level of recursive AST descent. Since Python ASTs can be quite deep and numerous across a large project, passing the underlying generator directly prevents unnecessary memory allocations and garbage collector pressure.

📊 Impact: Reduces intermediate object allocations for AST branches during recursive tree walks. Faster, lower-memory taint analysis.

🔬 Measurement: Verifiable via memory profiling on large ASTs or running standard pytest benchmarks (performance parity check). Tests run fully cleanly after this adjustment.


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

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 lite review requested due to automatic review settings August 7, 2026 16:41

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 reduces memory allocations during recursive Python AST traversals in the taint scanner by avoiding repeated list(ast.iter_child_nodes(...)) materialization and instead passing the child-node iterator through the recursion.

Changes:

  • Updated _assignment_callee and _collect_return_paths to accept Iterable[ast.AST] and recurse using ast.iter_child_nodes(node) directly.
  • Added a Bolt note documenting the “avoid eager AST child list materialization” performance guideline.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/wardline/scanner/taint/variable_level.py Switches recursive AST traversal helpers to take Iterable and passes ast.iter_child_nodes() directly to reduce per-level allocations.
.jules/bolt.md Documents the AST traversal performance guideline that motivates the change.
Suppressed comments (1)

src/wardline/scanner/taint/variable_level.py:2512

  • The new _assignment_callee(...) call is inlined onto one long line, while nearby calls in this module use multi-line formatting. Reformatting this call improves readability and avoids potential line-length/lint issues without reintroducing eager list materialization.
        # ⚡ Bolt: pass generator directly instead of list(ast.iter_child_nodes()) to avoid memory allocations
        nested = _assignment_callee(ast.iter_child_nodes(node), name, worst, function_taint, taint_map, var_taints)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 2477 to 2479
def _assignment_callee(
nodes: list[ast.AST],
nodes: Iterable[ast.AST],
name: str,
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