⚡ Optimize PathBuf clones in graph traversal#133
Conversation
Refactor `find_affected_files` to reduce memory allocations: - Remove redundant `visited` set (use `affected` set instead). - Use `VecDeque<&PathBuf>` to avoid cloning paths during queue processing. - Ensure only one `clone()` per unique affected node is performed. 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 GuideOptimizes the DependencyGraph::find_affected_files BFS traversal to avoid redundant PathBuf cloning and removes the separate visited set by operating on references and merging state into a single affected set. Class diagram for DependencyGraph and related types in optimized traversalclassDiagram
class DependencyGraph {
+find_affected_files(changed_files: RapidSet_PathBuf) RapidSet_PathBuf
+get_dependents(file: PathBuf_ref) Iterator_DependencyEdge
}
class RapidSet_PathBuf {
}
class DependencyEdge {
+from: PathBuf
+effective_strength() DependencyStrength
}
class DependencyStrength {
<<enumeration>>
Strong
Weak
}
class PathBuf {
}
class Iterator_DependencyEdge {
}
class VecDeque_PathBuf_ref {
}
DependencyGraph --> RapidSet_PathBuf : uses
DependencyGraph --> Iterator_DependencyEdge : iterates
DependencyGraph --> VecDeque_PathBuf_ref : queue
DependencyEdge --> PathBuf : owns
DependencyEdge --> DependencyStrength : labeled_by
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
Optimizes DependencyGraph::find_affected_files traversal by reducing PathBuf cloning during BFS over reverse dependency edges in the incremental analysis graph.
Changes:
- Replaced the owned
VecDeque<PathBuf>queue with a reference-basedVecDeque<&PathBuf>. - Removed the separate
visitedset by usingaffectedas the visited/output set. - Avoided cloning when enqueuing dependents by pushing references to
edge.from.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for edge in self.get_dependents(file) { | ||
| if edge.effective_strength() == DependencyStrength::Strong { | ||
| queue.push_back(edge.from.clone()); | ||
| queue.push_back(&edge.from); | ||
| } |
There was a problem hiding this comment.
Dependents are enqueued unconditionally (queue.push_back(&edge.from)), so the same path can be pushed many times in fan-in/diamond graphs, causing extra queue churn and (due to the clone-on-pop) extra allocations. To keep the traversal closer to “one clone per unique affected node”, skip enqueuing when affected already contains edge.from (or maintain a separate lightweight visited check before pushing).
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Fixed in a91cd43. Dependents are now only enqueued when affected doesn't already contain them, eliminating duplicate queue entries in fan-in/diamond graphs. The guard is applied consistently alongside the existing contains check at dequeue time.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
… churn Agent-Logs-Url: https://github.com/knitli/thread/sessions/92b7ba36-beb7-4460-8dfd-629b39468071 Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
…6233466 Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
find_affected_filestraversalaffectedsetthread-languagecompilation error is unrelated to changes⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.