Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions crates/flow/src/incremental/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,17 @@ impl DependencyGraph {
/// ```
pub fn find_affected_files(&self, changed_files: &RapidSet<PathBuf>) -> RapidSet<PathBuf> {
let mut affected = thread_utilities::get_set();
let mut visited = thread_utilities::get_set();
let mut queue: VecDeque<PathBuf> = changed_files.iter().cloned().collect();
let mut queue: VecDeque<&PathBuf> = changed_files.iter().collect();

while let Some(file) = queue.pop_front() {
if !visited.insert(file.clone()) {
if !affected.insert(file.clone()) {
continue;
}
Comment on lines +274 to 276
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

affected.insert(file.clone()) clones the PathBuf even when the file was already seen (because the clone happens before insert can return false). Since this PR is optimizing allocations, consider checking affected.contains(file) first and only cloning on the first visit so duplicates in the queue don't allocate and then immediately drop.

Suggested change
if !affected.insert(file.clone()) {
continue;
}
if affected.contains(file) {
continue;
}
affected.insert(file.clone());

Copilot uses AI. Check for mistakes.

affected.insert(file.clone());

// Follow reverse edges (files that depend on this file)
for edge in self.get_dependents(&file) {
for edge in self.get_dependents(file) {
if edge.effective_strength() == DependencyStrength::Strong {
queue.push_back(edge.from.clone());
queue.push_back(&edge.from);
}
Comment on lines +279 to 282
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
}
}
Expand Down
Loading