summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2021-06-07 09:39:30 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2021-06-07 09:39:30 +0800
commitfe9611a7fd9a1592cc1a4517948b4a32fba904c9 (patch)
tree88d3e1f5095760d3ded974711e81aa22abcf94a7 /src/main.rs
parentc3c103eebd82fc729788694a9f3bfd4ded855cf8 (diff)
Set default processor count on Apple Silicon in a way that won't be totally wrong in future
Soon new hardware will be revealed which probably acts differently.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index aa9d82e..1f523ba 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,12 +17,48 @@ fn stderr_if_tty() -> Option<io::Stderr> {
}
}
+#[cfg(not(all(target_os = "macos", target_arch = "aarch64"),))]
+fn derive_default_threads(threads: usize) -> usize {
+ threads
+}
+
+/// On Apple Silicon, high-efficiency cores make file accesses slower over all, so avoid over committing for
+/// this one.
+///
+/// On macos with apple silicon, the IO subsystem is entirely different and one thread can mostly max it out.
+/// Thus using more threads just burns energy unnecessarily.
+/// It's notable that `du` is very fast even on a single core and more power efficient than dua with a single core.
+/// The default of '4' seems related to the amount of performance cores present in the system.
+/// On everything else, it's usually a good idea to use as many threads as possible for noticeable speedups.
+#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
+fn derive_default_threads(threads: usize) -> usize {
+ use sysinfo::{ProcessorExt, RefreshKind, SystemExt};
+ if threads == 0 {
+ sysinfo::System::new_with_specifics(RefreshKind::new().with_cpu())
+ .get_processors()
+ .get(0)
+ .map_or(0, |p| match p.get_brand() {
+ "Apple M1" => 4,
+ other => {
+ eprintln!(
+ "Couldn't auto-configure correct amount of threads for {}",
+ other
+ );
+ 0
+ }
+ })
+ } else {
+ threads
+ }
+}
+
fn main() -> Result<()> {
use options::Command::*;
let opt: options::Args = options::Args::parse_from(wild::args_os());
+ let threads = derive_default_threads(opt.threads);
let walk_options = dua::WalkOptions {
- threads: opt.threads,
+ threads,
byte_format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric),
apparent_size: opt.apparent_size,
count_hard_links: opt.count_hard_links,