Skip to content

⚡ Bolt: [performance improvement] Avoid eager list materialization during AST traversal - #130

Open
tachyon-beep wants to merge 1 commit into
mainfrom
bolt-optimize-ast-traversal-3408277797811974874
Open

⚡ Bolt: [performance improvement] Avoid eager list materialization during AST traversal#130
tachyon-beep wants to merge 1 commit into
mainfrom
bolt-optimize-ast-traversal-3408277797811974874

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

💡 What: Modified AST traversal functions _assignment_callee and _collect_return_paths in src/wardline/scanner/taint/variable_level.py to accept Iterable[ast.AST] instead of list[ast.AST], removing the eager list() materialization of ast.iter_child_nodes(node) and func_node.body.

🎯 Why: Eagerly converting child node generators to lists at every node during AST traversal creates unnecessary shallow copies and causes excessive memory allocation, which degrades performance especially on large or deep syntax trees.

📊 Impact: Reduces memory overhead and avoids redundant list allocations during static taint analysis traversal. By yielding and iterating directly, the garbage collector has less work to do and memory usage stays flatter.

🔬 Measurement: The optimization preserves exact behavior (verified via the test suite) while improving the efficiency of the compute_return_taint and compute_return_callee analysis paths. Measuring peak memory usage during large codebase scans will show the reduction in memory pressure.


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

Modified `_assignment_callee` and `_collect_return_paths` in `src/wardline/scanner/taint/variable_level.py` to accept `Iterable[ast.AST]` instead of `list[ast.AST]`. This allows passing the result of `ast.iter_child_nodes()` directly without wrapping it in a `list()`, reducing memory allocation and overhead during deep AST traversals.

Co-authored-by: tachyon-beep <544926+tachyon-beep@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 1, 2026 16:26
@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 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

Improves AST traversal performance in the taint scanner by eliminating repeated eager list materialization during recursive walks, reducing per-node allocations and memory churn on large syntax trees.

Changes:

  • Updated _assignment_callee and _collect_return_paths to accept Iterable[ast.AST] and pass ast.iter_child_nodes(node) directly (no list(...) copies).
  • Removed list(func_node.body) materialization in compute_return_taint and compute_return_callee.
  • Added a short performance note in .jules/bolt.md documenting the “avoid eager list materialization” traversal guideline.

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 Avoids eager list creation in recursive AST traversal helpers to reduce memory overhead in return-taint analysis paths.
.jules/bolt.md Documents the learned performance guideline for AST traversal to prevent reintroducing eager list materialization.

💡 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