⚡ Bolt: [performance improvement] eliminate redundant PathBuf allocations in tarjan dfs#166
⚡ Bolt: [performance improvement] eliminate redundant PathBuf allocations in tarjan dfs#166bashandbone wants to merge 1 commit intomainfrom
Conversation
… redundant PathBuf allocations By switching to owned PathBuf instances purely for insertion, and utilizing &Path for all subsequent read/write `HashMap` interactions, we prevent repeated heap allocations taking place during every node evaluation within O(V+E) traversal. 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 guide (collapsed on small PRs)Reviewer's GuideRefactors the Tarjan DFS implementation in InvalidationDetector to avoid repeated PathBuf allocations by reusing a single owned PathBuf for the current node and using borrowed &Path for map lookups, improving performance and memory usage during graph traversal. Class diagram for InvalidationDetector.tarjan_dfs PathBuf allocation refactorclassDiagram
class InvalidationDetector {
+tarjan_dfs(v: &Path, state: &mut TarjanState, sccs: &mut Vec~Vec_PathBuf~~)
}
class TarjanState {
+index_counter: usize
+indices: HashMap~PathBuf, usize~
+lowlinks: HashMap~PathBuf, usize~
+stack: Vec~PathBuf~
+on_stack: HashSet~PathBuf~
}
InvalidationDetector --> TarjanState : uses
InvalidationDetector --> Path : traverses
TarjanState --> PathBuf : owns_keys
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’s SCC DFS in InvalidationDetector by removing per-edge PathBuf allocations during RapidMap lookups, leveraging borrowed &Path queries against RapidMap<PathBuf, _>.
Changes:
- Avoid repeated
v.to_path_buf()allocations intarjan_dfswhen updating/readingindicesandlowlinks. - Introduce a single
v_ownedallocation per visited vertex for initial insertions/pushes while keeping subsequent lookups borrowed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
💡 What: Optimized the
tarjan_dfsgraph traversal function insideInvaldationDetectorto stop redundantly allocatingPathBufequivalents when conducting map lookups.🎯 Why: Creating an owned instance (like
.to_path_buf()) purely to use in hash map query contexts triggers expensive heap memory operations on every iteration. Since standard library Map/Set configurations usingRapidHashimplement standardBorrow<Path>, it's natively supported to traverse graphs using borrowed&Pathvalues.📊 Impact: Exponential reduction in total memory allocated over heap boundaries on large directed graphs, reducing typical evaluation overhead on scale.
🔬 Measurement: Verify changes mathematically through
O(V)allocation constraint over historicalO(E), and logically passing through checking test behavior (e.g.,cargo test -p thread-flow --test invalidation_tests).PR created automatically by Jules for task 8933233122411922861 started by @bashandbone
Summary by Sourcery
Enhancements: