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 `<unknown>`

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-26 13:44:34 +01:00
committed by GitHub
parent d6b31d8932
commit 2471ae451c
8 changed files with 34 additions and 3 deletions

2
Cargo.lock generated
View File

@@ -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",

View File

@@ -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

View File

@@ -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({

View File

@@ -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);

View File

@@ -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(

View File

@@ -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

View File

@@ -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 {

View File

@@ -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();