From 015d03751ca3a45c4535674ecd3922defece98f3 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 15 Jun 2026 18:58:56 -0700 Subject: [PATCH] Library scan: leave one core free at startup The startup channel scan used available_parallelism() (every core), which could briefly peg the whole box on a cold/large library. Cap it at cores-1 so the machine stays responsive; the scan is disk-I/O-bound and runs as a background task, so one fewer thread costs little. Mirrors the headroom the fingerprint pass and thumbnail pool already leave. Co-Authored-By: Claude Opus 4.8 --- src/library.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/library.rs b/src/library.rs index 30d32b9..ab6b432 100644 --- a/src/library.rs +++ b/src/library.rs @@ -224,10 +224,11 @@ pub fn scan_channels_with_cache(youtube_root: &Path, cache: Option<&Database>) - } } - let n_workers = std::thread::available_parallelism() - .map(|n| n.get()) - .unwrap_or(4) - .min(dirs.len().max(1)); + // Leave one core free so a cold/large scan doesn't peg every core and + // make the box unresponsive — this runs as a background task and the scan + // is mostly disk-I/O-bound anyway, so giving up one thread costs little. + let cores = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(4); + let n_workers = cores.saturating_sub(1).max(1).min(dirs.len().max(1)); // Hand each worker its own Database handle via .clone() (Arc inside, // cheap). Workers without a cache get None. let cache_handle: Option = cache.cloned();