Skip to content

Commit

Permalink
fix: on MacOS use only 3 threads by default.
Browse files Browse the repository at this point in the history
Otherwise, it would get very slow and the difference is enormous.
16 threads for example take 4.1s on a workload, whereas this only takes
550ms with 3 threads.
  • Loading branch information
Byron committed Dec 2, 2024
1 parent 6386036 commit 8933be4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ fn dft_format() -> ByteFormat {
}
}

/// For some reason, on MacOS, too many threads are bad and 3 is the best these days on M4.
/// On M1 it was more like 4, but close enough.
#[cfg(target_os = "macos")]
const DEFAULT_THREADS: usize = 3;

#[cfg(not(target_os = "macos"))]
const DEFAULT_THREADS: usize = 0;

/// A tool to learn about disk usage, fast!
#[derive(Debug, clap::Parser)]
#[clap(name = "dua", version)]
Expand All @@ -44,7 +52,7 @@ pub struct Args {

/// The amount of threads to use. Defaults to 0, indicating the amount of logical processors.
/// Set to 1 to use only a single thread.
#[clap(short = 't', long = "threads", default_value_t = 0)]
#[clap(short = 't', long = "threads", default_value_t = DEFAULT_THREADS)]
pub threads: usize,

/// The format with which to print byte counts.
Expand Down

0 comments on commit 8933be4

Please sign in to comment.