-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize graph traversal in find_affected_files by utilizing reference queues
#128
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
1a14b88
a052efd
93b9d65
f76be3d
c8451de
5f41f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use std::path::PathBuf; | ||
| use thread_flow::incremental::graph::DependencyGraph; | ||
| use thread_flow::incremental::types::{DependencyEdge, DependencyType}; | ||
| use thread_utilities::RapidSet; | ||
|
|
||
| use std::hint::black_box; | ||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||
|
|
||
| fn bench_find_affected_files(c: &mut Criterion) { | ||
| let mut graph = DependencyGraph::new(); | ||
| let num_files = 10000; | ||
| let deps_per_file = 10; | ||
|
|
||
| // Create nodes | ||
| for i in 0..num_files { | ||
| graph.add_node(&PathBuf::from(format!("file_{}.rs", i))); | ||
| } | ||
|
|
||
| // Create edges (linear chain with some random deps) | ||
| for i in 0..num_files { | ||
| for j in 1..=deps_per_file { | ||
| let dep_idx = (i + j) % num_files; | ||
| graph.add_edge(DependencyEdge::new( | ||
| PathBuf::from(format!("file_{}.rs", i)), | ||
| PathBuf::from(format!("file_{}.rs", dep_idx)), | ||
| DependencyType::Import, | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| let changed_files: RapidSet<PathBuf> = (0..10) | ||
| .map(|i| PathBuf::from(format!("file_{}.rs", i))) | ||
| .collect(); | ||
|
|
||
| c.bench_function("find_affected_files_10000_nodes", |b| { | ||
| b.iter(|| { | ||
| let _affected = graph.find_affected_files(black_box(&changed_files)); | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_find_affected_files); | ||
| criterion_main!(benches); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,21 +267,17 @@ impl DependencyGraph { | |
| /// assert!(affected.contains(&PathBuf::from("C"))); | ||
| /// ``` | ||
| 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 affected = changed_files.clone(); | ||
| let mut queue: VecDeque<&PathBuf> = changed_files.iter().collect(); | ||
|
Comment on lines
+270
to
+271
|
||
|
|
||
| while let Some(file) = queue.pop_front() { | ||
| if !visited.insert(file.clone()) { | ||
| continue; | ||
| } | ||
|
|
||
| affected.insert(file.clone()); | ||
|
|
||
| // Follow reverse edges (files that depend on this file) | ||
| for edge in self.get_dependents(&file) { | ||
| if edge.effective_strength() == DependencyStrength::Strong { | ||
| queue.push_back(edge.from.clone()); | ||
| for edge in self.get_dependents(file) { | ||
| if edge.effective_strength() == DependencyStrength::Strong | ||
| && !affected.contains(&edge.from) | ||
| { | ||
| affected.insert(edge.from.clone()); | ||
| queue.push_back(&edge.from); | ||
| } | ||
| } | ||
|
Comment on lines
+275
to
282
|
||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.