cli: Tweak default thread count logic
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tavian Barnes · committed by David Peter · parent 00b64f3 · Browse files · 2 files·+12 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+12 added−20 removed
- other:+12 added−20 removed
Provenance
- Commit
fea1622- Tree
64c0c83- Author
Tavian Barnes <tavianator@tavianator.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
00b64f3
2 files changed+12 added−20 removed
modified:src/cli.rs+7 added-17 removed
713 unmodified lines714 /// Get the default number of threads to use, if not explicitly specified.715 fn default_num_threads() -> NonZeroUsize {716 // If we can't get the amount of parallelism for some reason, then717 // default to a single thread, because that is safe.718- // Note that the minimum value for a NonZeroUsize is 1.719- // Unfortunately, we can't do `NonZeroUsize::new(1).unwrap()`720- // in a const context.721- const FALLBACK_PARALLELISM: NonZeroUsize = NonZeroUsize::MIN;722- // As the number of threads increases, the startup time suffers from723- // initializing the threads, and we get diminishing returns from additional724- // parallelism. So set a maximum number of threads to use by default.725- //726- // This value is based on some empirical observations, but the ideal value727- // probably depends on the exact hardware in use.728- //729- // Safety: The literal "20" is known not to be zero.730- const MAX_DEFAULT_THREADS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(20) };718+ let fallback = NonZeroUsize::MIN;719+ // To limit startup overhead on massively parallel machines, don't use more720+ // than 64 threads.721+ let limit = NonZeroUsize::new(64).unwrap();722 732- std::cmp::min(733- std::thread::available_parallelism().unwrap_or(FALLBACK_PARALLELISM),734- MAX_DEFAULT_THREADS,735- )723+ std::thread::available_parallelism()724+ .unwrap_or(fallback)725+ .min(limit)726 }727 728 #[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]729 pub enum FileType {156 unmodified linesmodified:CHANGELOG.md+5 added-3 removed
3 unmodified lines4 5 - Breaking: `.git/` is now ignored by default when using `--hidden` / `-H`, use `--no-ignore` / `-I` or6 `--no-ignore-vcs` to override, see #1387 and #1396 (@skoriop)7 8-8 ## Bugfixes9 10 - Fix `NO_COLOR` support, see #1421 (@acuteenvy)11 12 ## Changes13 15-- The default number of threads is now constrained to be at most 16. This should improve startup time on16- systems with many CPU cores. (#1203)14+- Performance has been significantly improved, both due to optimizations in the underlying `ignore`15+ crate (#1429), and in `fd` itself (#1422).16 17+- The default number of threads is now constrained to be at most 64. This should improve startup time on18+ systems with many CPU cores. (#1203, #1412, #1431)19+20 ## Other21 22 # v8.7.123 693 unmodified lines