diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-12-13 20:17:44 +0100 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-12-13 20:17:44 +0100 |
commit | f073375938f742db3259ec284c3c0d4a56fd0077 (patch) | |
tree | b0639d3b1c910e98220e657391cc7542150da860 | |
parent | d1cdfa1d682962deea5a0c48b90589becd6e19dc (diff) |
feat: Remove the handbrake on MacOS which can now deliver the expected performance.
Previously it would limit itself to only using 4 threads as it would
use a lot of time in user space. This has changed now, and the traversal
itself is much more efficient (even though it could definitely be more
efficient when comparing to `pdu`).
In any case, counting performance should now greatly improve on M1
MacOS machines.
-rw-r--r-- | Cargo.lock | 30 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/main.rs | 38 |
3 files changed, 1 insertions, 70 deletions
@@ -97,12 +97,6 @@ dependencies = [ ] [[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - -[[package]] name = "crossbeam" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -239,7 +233,6 @@ dependencies = [ "owo-colors", "petgraph", "pretty_assertions", - "sysinfo", "trash", "tui", "tui-react", @@ -457,15 +450,6 @@ dependencies = [ ] [[package]] -name = "ntapi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" -dependencies = [ - "winapi", -] - -[[package]] name = "num_cpus" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -746,20 +730,6 @@ dependencies = [ ] [[package]] -name = "sysinfo" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d08ba83d6dde63d053e42d7230f0dc7f8d8efeb8d30d3681580d158156461ba" -dependencies = [ - "cfg-if", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "winapi", -] - -[[package]] name = "termcolor" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -38,9 +38,6 @@ open = { version = "3.0", optional = true } wild = "2.0.4" owo-colors = "3.5.0" -[target.'cfg(all(target_os = "macos", target_arch = "aarch64"))'.dependencies] -sysinfo = { version = "0.27.0", default-features = false } - [[bin]] name="dua" path="src/main.rs" diff --git a/src/main.rs b/src/main.rs index a7fd3eb..2aac48c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,48 +17,12 @@ 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::{CpuExt, CpuRefreshKind}; - use sysinfo::{RefreshKind, SystemExt}; - if threads == 0 { - let system = sysinfo::System::new_with_specifics( - RefreshKind::new().with_cpu(CpuRefreshKind::default()), - ); - if system.global_cpu_info().brand().starts_with("Apple M") { - 4 - } else { - eprintln!( - "Couldn't auto-configure correct amount of threads for {}. Create an issue here: https://github.com/byron/dua-cli/issues", - system.global_cpu_info().brand() - ); - 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, + threads: opt.threads, byte_format: opt.format.into(), apparent_size: opt.apparent_size, count_hard_links: opt.count_hard_links, |