-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize PathBuf clones in graph traversal #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
|
||
| 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
|
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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 thePathBufeven when the file was already seen (because the clone happens beforeinsertcan return false). Since this PR is optimizing allocations, consider checkingaffected.contains(file)first and only cloning on the first visit so duplicates in the queue don't allocate and then immediately drop.