diff --git a/Cargo.lock b/Cargo.lock index fa1136f..83d3637 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1537,6 +1537,7 @@ dependencies = [ "mime_guess", "notify-debouncer-full", "notify-rust", + "num_cpus", "once_cell", "open", "ordermap", diff --git a/Cargo.toml b/Cargo.toml index 3a3b26d..4b6b56a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ uzers = "0.12.1" md-5 = "0.10.6" png = "0.17.16" jxl-oxide = { version = "0.12.2", features = ["image"] } +num_cpus = "1.17.0" # Completion-based IO runtime to enable io_uring / IOCP file IO support. [dependencies.compio] diff --git a/src/tab.rs b/src/tab.rs index 6a81270..4f3f865 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -95,6 +95,11 @@ const MAX_SEARCH_RESULTS: usize = 200; //TODO: configurable thumbnail size? const THUMBNAIL_SIZE: u32 = (ICON_SIZE_GRID as u32) * (ICON_SCALE_MAX as u32); +pub static THUMB_SEMAPHORE: LazyLock = LazyLock::new(|| { + tokio::sync::Semaphore::const_new(num_cpus::get()) +}); + + pub(crate) static SORT_OPTION_FALLBACK: LazyLock> = LazyLock::new(|| { HashMap::from_iter(dirs::download_dir().into_iter().map(|dir| { @@ -5634,6 +5639,7 @@ impl Tab { let message = { let path = path.clone(); + _ = THUMB_SEMAPHORE.acquire().await; tokio::task::spawn_blocking(move || { let start = Instant::now(); let thumbnail = ItemThumbnail::new(