From 2471ae451c8abca322e384b0f034d6cfd0ec70b6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 26 Oct 2025 13:44:34 +0100 Subject: [PATCH] Pre-initialize global rayon threadpool (#41226) We only use it a handful of times and the default amount of threads (logical cpu core number) its spawns is overkill for this. This also gives the threads names oppose to being labeled `` Release Notes: - N/A *or* Added/Fixed/Improved ... --- Cargo.lock | 2 ++ crates/cli/Cargo.toml | 1 + crates/cli/src/main.rs | 6 ++++++ crates/editor/src/display_map.rs | 9 +++++++++ crates/editor/src/editor.rs | 4 ++-- crates/remote_server/Cargo.toml | 1 + crates/remote_server/src/unix.rs | 6 ++++++ crates/text/src/text.rs | 8 +++++++- 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4febdba89abad2b2103f27c19f0c3b4fee11bb7..0d5fcbfa7ad4fa4db45af216c1d2d0a3ad52123c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3073,6 +3073,7 @@ dependencies = [ "parking_lot", "paths", "plist", + "rayon", "release_channel", "serde", "tempfile", @@ -13890,6 +13891,7 @@ dependencies = [ "pretty_assertions", "project", "proto", + "rayon", "release_channel", "remote", "reqwest_client", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ea4a8de290921e1c7d4d4eb70a271799a1761dc2..54f7ec4f5315a6529579353f3aa489925534d4ba 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -32,6 +32,7 @@ release_channel.workspace = true serde.workspace = true util.workspace = true tempfile.workspace = true +rayon.workspace = true [target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies] exec.workspace = true diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 64a342a332f2c1b896afe58dda0e7156304e8116..bb2f2effbbf8ff0d8995b8607c1ce2ddff66ac0c 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -356,6 +356,12 @@ fn main() -> Result<()> { "Dev servers were removed in v0.157.x please upgrade to SSH remoting: https://zed.dev/docs/remote-development" ); + rayon::ThreadPoolBuilder::new() + .num_threads(4) + .thread_name(|ix| format!("RayonWorker{}", ix)) + .build_global() + .unwrap(); + let sender: JoinHandle> = thread::Builder::new() .name("CliReceiver".to_string()) .spawn({ diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index a6b3d904be94fdcab1b347f68c6c0b03ae091a04..f313535fca5ae40ab97d57c143dde85d278d6ac8 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -751,6 +751,7 @@ pub struct DisplaySnapshot { diagnostics_max_severity: DiagnosticSeverity, pub(crate) fold_placeholder: FoldPlaceholder, } + impl DisplaySnapshot { pub fn wrap_snapshot(&self) -> &WrapSnapshot { &self.block_snapshot.wrap_snapshot @@ -1408,6 +1409,14 @@ impl DisplaySnapshot { } } +impl std::ops::Deref for DisplaySnapshot { + type Target = BlockSnapshot; + + fn deref(&self) -> &Self::Target { + &self.block_snapshot + } +} + #[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)] pub struct DisplayPoint(BlockPoint); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c8b0cd37aeed0601c6402d2ad0f41cfa3a9ba56c..ae833d48fe56160eae5b12c5eb2960e9a542ba9f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -7945,7 +7945,7 @@ impl Editor { let snapshot = self.snapshot(window, cx); - let multi_buffer_snapshot = snapshot.display_snapshot.buffer_snapshot(); + let multi_buffer_snapshot = snapshot.buffer_snapshot(); let Some(project) = self.project() else { return breakpoint_display_points; }; @@ -7975,7 +7975,7 @@ impl Editor { let multi_buffer_anchor = Anchor::in_buffer(excerpt_id, buffer_snapshot.remote_id(), breakpoint.position); let position = multi_buffer_anchor - .to_point(multi_buffer_snapshot) + .to_point(&multi_buffer_snapshot) .to_display_point(&snapshot); breakpoint_display_points.insert( diff --git a/crates/remote_server/Cargo.toml b/crates/remote_server/Cargo.toml index 3d28f6ba565330a5fc3c0ea0249aaf760c880439..5034b24e0661eb87665d9b805b2bbc5d2ca577cd 100644 --- a/crates/remote_server/Cargo.toml +++ b/crates/remote_server/Cargo.toml @@ -65,6 +65,7 @@ util.workspace = true watch.workspace = true worktree.workspace = true thiserror.workspace = true +rayon.workspace = true [target.'cfg(not(windows))'.dependencies] crashes.workspace = true diff --git a/crates/remote_server/src/unix.rs b/crates/remote_server/src/unix.rs index 3cfb73adbb82af2d83182400d725d859ebad29f8..1a7dc8c9621354a385a65567960a6215f680528c 100644 --- a/crates/remote_server/src/unix.rs +++ b/crates/remote_server/src/unix.rs @@ -370,6 +370,12 @@ pub fn execute_run( let listeners = ServerListeners::new(stdin_socket, stdout_socket, stderr_socket)?; + rayon::ThreadPoolBuilder::new() + .num_threads(4) + .thread_name(|ix| format!("RayonWorker{}", ix)) + .build_global() + .unwrap(); + let (shell_env_loaded_tx, shell_env_loaded_rx) = oneshot::channel(); app.background_executor() .spawn(async { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index 9a81fc8e941ab4d3a0e16f817fc90fbb608ea84a..d9f0626016f6377228070a2f21f0721d92ec58aa 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -2291,7 +2291,13 @@ impl BufferSnapshot { insertion_cursor.prev(); } let insertion = insertion_cursor.item().expect("invalid insertion"); - assert_eq!(insertion.timestamp, anchor.timestamp, "invalid insertion"); + assert_eq!( + insertion.timestamp, + anchor.timestamp, + "invalid insertion for buffer {} with anchor {:?}", + self.remote_id(), + anchor + ); fragment_cursor.seek_forward(&Some(&insertion.fragment_id), Bias::Left); let fragment = fragment_cursor.item().unwrap();