Skip to content

⚡ Bolt: [performance improvement] optimize file path map lookups in invalidation detector#154

Open
bashandbone wants to merge 1 commit intomainfrom
bolt/optimize-tarjan-invalidation-16106423400975348129
Open

⚡ Bolt: [performance improvement] optimize file path map lookups in invalidation detector#154
bashandbone wants to merge 1 commit intomainfrom
bolt/optimize-tarjan-invalidation-16106423400975348129

Conversation

@bashandbone
Copy link
Copy Markdown
Contributor

@bashandbone bashandbone commented Apr 16, 2026

💡 What: Used borrowed &Path reference instead of owned PathBuf for HashMap existence and mutability checks in tarjan_dfs.
🎯 Why: Avoid O(E) unnecessary heap memory allocations of PathBuf within tight nested loops traversing nodes and edges of the invalidation graph.
📊 Impact: Considerably reduces memory pressure and allocation overhead during calculation of the increment invalidation sets.
🔬 Measurement: Verify using cargo test -p thread-flow --test invalidation_tests.


PR created automatically by Jules for task 16106423400975348129 started by @bashandbone

Summary by Sourcery

Optimize invalidation graph traversal to reduce allocation overhead and perform minor API and formatting cleanups.

Enhancements:

  • Use borrowed path references for index and lowlink lookups in the incremental invalidation detector to avoid unnecessary allocations.
  • Simplify rule-engine helper function signatures by removing unused lifetimes and taking borrowed references where appropriate.
  • Tidy formatting and chaining style in string content handling, assertions, and registration map access for improved readability.

…nvalidation detector

💡 What: Used borrowed `&Path` reference instead of owned `PathBuf` for HashMap existence and mutability checks in `tarjan_dfs`.
🎯 Why: Avoid O(E) unnecessary heap memory allocations of `PathBuf` within tight nested loops traversing nodes and edges of the invalidation graph.
📊 Impact: Considerably reduces memory pressure and allocation overhead during calculation of the increment invalidation sets.
🔬 Measurement: Verify using `cargo test -p thread-flow --test invalidation_tests`.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 18: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.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 16, 2026

Reviewer's Guide

Optimizes Tarjan DFS invalidation detection by switching HashMap lookups from owned PathBuf to borrowed &Path, and performs a few minor API and formatting cleanups across rule- and AST-related modules.

File-Level Changes

Change Details Files
Optimize Tarjan DFS invalidation detector by avoiding PathBuf allocations in hashmap lookups
  • Change lowlink and index map lookups in the Tarjan DFS to use &Path keys instead of allocating new PathBuf instances
  • Update all related get/get_mut calls in the DFS logic to accept borrowed path references
crates/flow/src/incremental/invalidation.rs
Minor API signature cleanups for rule-engine helpers
  • Remove unnecessary lifetime parameters from helper functions that only take shared references
  • Tighten parameter types from generic lifetimes to direct shared references for constraints and transforms
crates/rule-engine/src/check_var.rs
Style and readability updates in rule-engine and AST modules
  • Reformat chained iterator and collection expressions for better readability
  • Condense read-lock unwrap_or_else + clone chain into a single line without changing behavior
  • Reformat long assertions and chained method calls for consistency with rustfmt style
crates/ast-engine/src/tree_sitter/mod.rs
crates/rule-engine/src/rule/mod.rs
crates/rule-engine/src/rule/referent_rule.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In tarjan_dfs, you still perform multiple indices/lowlinks lookups for the same v (e.g., when computing v_index and v_lowlink at the end); consider caching these values or holding a single mutable reference per iteration to further cut down hashmap accesses and potential contention.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `tarjan_dfs`, you still perform multiple `indices`/`lowlinks` lookups for the same `v` (e.g., when computing `v_index` and `v_lowlink` at the end); consider caching these values or holding a single mutable reference per iteration to further cut down hashmap accesses and potential contention.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes Tarjan SCC traversal in the incremental invalidation detector by avoiding repeated PathBuf allocations during map lookups, alongside a few small refactors/formatting cleanups.

Changes:

  • Use borrowed &Path for indices/lowlinks get/get_mut lookups in tarjan_dfs to avoid per-edge PathBuf allocations.
  • Remove unnecessary explicit lifetimes in internal variable-check helper functions.
  • Minor formatting-only refactors in a few Rust modules/tests.

Reviewed changes

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

Show a summary per file
File Description
crates/flow/src/incremental/invalidation.rs Avoids v.to_path_buf() allocations on tight-loop map lookups in Tarjan DFS.
crates/rule-engine/src/check_var.rs Simplifies helper fn signatures by removing redundant lifetimes.
crates/rule-engine/src/rule/referent_rule.rs Collapses a read/clone chain into a single line (no behavior change).
crates/rule-engine/src/rule/mod.rs Reformats defined_vars mapping for readability (no behavior change).
crates/ast-engine/src/tree_sitter/mod.rs Minor formatting refactor and rewraps an assertion for readability (no behavior change).

💡 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