diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 08:25:14 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 08:25:14 +0530 |
commit | 95685f1387b74e2bbd7c1e67d383cd5861aa3451 (patch) | |
tree | 9deedac585a47e026655bb272b102b2295d55534 | |
parent | 24e1e2cc3345e6891ec12c821b425ebc91f41d8d (diff) |
Assure we don't keep threads around unnecessarily in interactive mode
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/traverse.rs | 10 |
2 files changed, 8 insertions, 3 deletions
@@ -23,6 +23,7 @@ itertools = "0.8.0" open = "1.2.2" log = "0.4.6" tui-react = { path = "./tui-react", version = "0.1" } +num_cpus = "1.10.0" [[bin]] name="dua" diff --git a/src/traverse.rs b/src/traverse.rs index d6ef957..dc28579 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -35,7 +35,7 @@ pub struct Traversal { impl Traversal { pub fn from_walk( - options: WalkOptions, + mut walk_options: WalkOptions, input: Vec<PathBuf>, mut update: impl FnMut(&Traversal) -> Result<(), Error>, ) -> Result<Traversal, Error> { @@ -73,10 +73,14 @@ impl Traversal { const INITIAL_CHECK_INTERVAL: usize = 500; let mut check_instant_every = INITIAL_CHECK_INTERVAL; let mut last_seen_eid; - + if walk_options.threads == 0 { + // avoid using the global rayon pool, as it will keep a lot of threads alive after we are done. + // Also means that we will spin up a bunch of threads per root path, instead of reusing them. + walk_options.threads = num_cpus::get_physical(); + } for path in input.into_iter() { last_seen_eid = 0; - for (eid, entry) in options + for (eid, entry) in walk_options .iter_from_path(path.as_ref()) .into_iter() .enumerate() |