From 01ac5fcb345107930fca3b861584e878f6b40f7f Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:43:43 +0000 Subject: [PATCH] linux: Spawn at least two background threads (#44110) (cherry-pick to preview) (#44157) Cherry-pick of #44110 to preview ---- Related to https://github.com/zed-industries/zed/pull/44109, https://github.com/zed-industries/zed/issues/43884, https://github.com/zed-industries/zed/issues/43809. In the Linux dispatcher, we create one background thread per CPU, but when a single core is available, having a single background thread significantly hinders the perceived performance of Zed. This is particularly helpful when SSH remoting to low-resource servers. We may want to bump this to more than two threads actually, but I wanted to be conservative, and this seems to make a big difference already. Release Notes: - N/A Co-authored-by: Agus Zubiaga --- crates/gpui/src/platform/linux/dispatcher.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/linux/dispatcher.rs b/crates/gpui/src/platform/linux/dispatcher.rs index c300109ffe32b3537acbbca47b4c39674cad2fd1..d0c32140f3642e037df326f4e2beae16c59dd883 100644 --- a/crates/gpui/src/platform/linux/dispatcher.rs +++ b/crates/gpui/src/platform/linux/dispatcher.rs @@ -26,12 +26,13 @@ pub(crate) struct LinuxDispatcher { main_thread_id: thread::ThreadId, } +const MIN_THREADS: usize = 2; + impl LinuxDispatcher { pub fn new(main_sender: Sender) -> Self { let (background_sender, background_receiver) = flume::unbounded::(); - let thread_count = std::thread::available_parallelism() - .map(|i| i.get()) - .unwrap_or(1); + let thread_count = + std::thread::available_parallelism().map_or(MIN_THREADS, |i| i.get().max(MIN_THREADS)); let mut background_threads = (0..thread_count) .map(|i| {