-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use scoped threads for parallelism (#117)
* Allow `RustyWind` to be cloned * Use a scoped_thread instead of actors * Add debug log to show how many files its checking
- Loading branch information
1 parent
3af70d9
commit d2057ce
Showing
6 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// Heard is a struct that handles running the rustywind on a list of files | ||
/// in parallel. It uses the num_cpus crate to determine the number of | ||
/// physical cores on the machine. It then spawns a thread for each core | ||
/// and runs the rustywind on the file paths. | ||
use crate::options::Options; | ||
use std::{path::PathBuf, sync::Arc}; | ||
|
||
#[derive(Debug)] | ||
pub struct Heard { | ||
cpus: usize, | ||
options: Arc<Options>, | ||
} | ||
|
||
impl Heard { | ||
pub fn new(options: Arc<Options>) -> Self { | ||
let cpus = num_cpus::get_physical(); | ||
Self { cpus, options } | ||
} | ||
|
||
pub fn run_on_file_paths(self, file_paths: Vec<PathBuf>) { | ||
log::debug!("checking {} files", file_paths.len()); | ||
|
||
let total_chunks = self.cpus; | ||
let chunks_of = file_paths.len() / total_chunks; | ||
let options = &self.options; | ||
|
||
std::thread::scope(|s| { | ||
file_paths.chunks(chunks_of).for_each(|chunk| { | ||
s.spawn(|| { | ||
run_on_file_paths(chunk, options); | ||
}); | ||
}); | ||
}) | ||
} | ||
} | ||
|
||
fn run_on_file_paths(file_paths: &[PathBuf], options: &Options) { | ||
for file_path in file_paths { | ||
crate::run_on_file_path(file_path, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters