mirror of https://github.com/sharkdp/fd.git
cli: Tweak default thread count logic
This commit is contained in:
parent
00b64f3ccb
commit
fea1622724
|
@ -5,15 +5,17 @@
|
|||
- Breaking: `.git/` is now ignored by default when using `--hidden` / `-H`, use `--no-ignore` / `-I` or
|
||||
`--no-ignore-vcs` to override, see #1387 and #1396 (@skoriop)
|
||||
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Fix `NO_COLOR` support, see #1421 (@acuteenvy)
|
||||
|
||||
## Changes
|
||||
|
||||
- The default number of threads is now constrained to be at most 16. This should improve startup time on
|
||||
systems with many CPU cores. (#1203)
|
||||
- Performance has been significantly improved, both due to optimizations in the underlying `ignore`
|
||||
crate (#1429), and in `fd` itself (#1422).
|
||||
|
||||
- The default number of threads is now constrained to be at most 64. This should improve startup time on
|
||||
systems with many CPU cores. (#1203, #1412, #1431)
|
||||
|
||||
## Other
|
||||
|
||||
|
|
24
src/cli.rs
24
src/cli.rs
|
@ -715,24 +715,14 @@ impl Opts {
|
|||
fn default_num_threads() -> NonZeroUsize {
|
||||
// If we can't get the amount of parallelism for some reason, then
|
||||
// default to a single thread, because that is safe.
|
||||
// Note that the minimum value for a NonZeroUsize is 1.
|
||||
// Unfortunately, we can't do `NonZeroUsize::new(1).unwrap()`
|
||||
// in a const context.
|
||||
const FALLBACK_PARALLELISM: NonZeroUsize = NonZeroUsize::MIN;
|
||||
// As the number of threads increases, the startup time suffers from
|
||||
// initializing the threads, and we get diminishing returns from additional
|
||||
// parallelism. So set a maximum number of threads to use by default.
|
||||
//
|
||||
// This value is based on some empirical observations, but the ideal value
|
||||
// probably depends on the exact hardware in use.
|
||||
//
|
||||
// Safety: The literal "20" is known not to be zero.
|
||||
const MAX_DEFAULT_THREADS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(20) };
|
||||
let fallback = NonZeroUsize::MIN;
|
||||
// To limit startup overhead on massively parallel machines, don't use more
|
||||
// than 64 threads.
|
||||
let limit = NonZeroUsize::new(64).unwrap();
|
||||
|
||||
std::cmp::min(
|
||||
std::thread::available_parallelism().unwrap_or(FALLBACK_PARALLELISM),
|
||||
MAX_DEFAULT_THREADS,
|
||||
)
|
||||
std::thread::available_parallelism()
|
||||
.unwrap_or(fallback)
|
||||
.min(limit)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
|
||||
|
|
Loading…
Reference in New Issue