⚡ Bolt: [Performance: Defer Allocation during Traversal]#246
⚡ Bolt: [Performance: Defer Allocation during Traversal]#246bashandbone wants to merge 1 commit into
Conversation
Refactors `tarjan_dfs` inside `crates/flow/src/incremental/invalidation.rs` to defer `PathBuf` heap allocations. Allocates `PathBuf` exactly once upon node initialization and replaces `v.to_path_buf()` on inner loop lookups with the borrowed reference `v`. This eliminates redundant `O(E)` memory heap allocations per node visited. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideRefactors the Tarjan DFS invalidation traversal to avoid repeated PathBuf allocations by borrowing Path keys, and applies minor formatting/unwrap_or_else style cleanups in AST and rule engine modules. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes Tarjan SCC traversal in the incremental invalidation detector by avoiding repeated PathBuf allocations during hot-path map lookups (leveraging borrowed &Path lookups against RapidMap<PathBuf, _> / RapidSet<PathBuf>). It also includes a few rustfmt-style formatting cleanups in unrelated modules.
Changes:
- Refactor
tarjan_dfsto reuse an ownedPathBuffor inserts and use borrowed&Pathfor repeatedget/get_mutlookups in the DFS inner loop. - Minor formatting-only adjustments in rule-engine and tree-sitter modules/tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/flow/src/incremental/invalidation.rs | Reduce allocations in Tarjan DFS by avoiding v.to_path_buf() in repeated HashMap/HashSet lookups. |
| crates/rule-engine/src/rule/referent_rule.rs | Formatting-only refactor (single-line chaining). |
| crates/rule-engine/src/rule/mod.rs | Formatting-only refactor for defined_vars match arm. |
| crates/ast-engine/src/tree_sitter/mod.rs | Formatting-only refactor of unwrap_or_else and a test assertion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let index = state.index_counter; | ||
| state.indices.insert(v.to_path_buf(), index); | ||
| state.lowlinks.insert(v.to_path_buf(), index); | ||
| // ⚡ Bolt: Defer allocation by allocating the PathBuf exactly once instead of on every map/set operation |
💡 What: Refactored
tarjan_dfsincrates/flow/src/incremental/invalidation.rsto eliminate redundant heap allocations when checking HashMaps inside the hot path. Leverages Rust'sBorrow<Path>trait by passing the referencevinstead of callingv.to_path_buf()repeatedly.🎯 Why: During the graph traversal algorithm, the string/path was being allocated on the heap inside a loop just to check against existing
HashMapkeys. This caused unnecessary memory allocationsO(E)instead ofO(V).📊 Impact: Reduces memory churn and heap allocations significantly during DAG traversals, speeding up incremental analysis by removing
O(E)allocations per component.🔬 Measurement: Verified that tests pass via
cargo test -p thread-flow --test invalidation_testsand ensured correct behavior with no performance regressions.PR created automatically by Jules for task 16447134283470556383 started by @bashandbone
Summary by Sourcery
Reduce heap allocations in incremental invalidation DFS traversal and apply minor style cleanups across AST and rule engine modules.
Enhancements:
Chores: