Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Pre-initialize global rayon threadpool (#41226)

Lukas Wirth2471ae451c8a
diff --git a/Cargo.lock b/Cargo.lock
index b4febdba89a..0d5fcbfa7ad 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 ea4a8de2909..54f7ec4f531 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 64a342a332f..bb2f2effbbf 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<anyhow::Result<()>> = 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 a6b3d904be9..f313535fca5 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 c8b0cd37aee..ae833d48fe5 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 3d28f6ba565..5034b24e066 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 3cfb73adbb8..1a7dc8c9621 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 9a81fc8e941..d9f0626016f 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();