Skip to content

Commit 2c171f8

Browse files
committed
Give rayon workers better names
1 parent ca9d3fb commit 2c171f8

File tree

2 files changed

+69
-42
lines changed

2 files changed

+69
-42
lines changed

crates/project-model/src/workspace.rs

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! metadata` or `rust-project.json`) into representation stored in the salsa
33
//! database -- `CrateGraph`.
44
5+
use std::thread::Builder;
56
use std::{collections::VecDeque, fmt, fs, iter, ops::Deref, sync, thread};
67

78
use anyhow::Context;
@@ -301,31 +302,39 @@ impl ProjectWorkspace {
301302
// We can speed up loading a bit by spawning all of these processes in parallel (especially
302303
// on systems were process spawning is delayed)
303304
let join = thread::scope(|s| {
304-
let rustc_cfg = s.spawn(|| {
305-
rustc_cfg::get(toolchain_config, targets.first().map(Deref::deref), extra_env)
306-
});
307-
let target_data = s.spawn(|| {
308-
target_data::get(
309-
toolchain_config,
310-
targets.first().map(Deref::deref),
311-
extra_env,
312-
).inspect_err(|e| {
313-
tracing::error!(%e, "failed fetching data layout for {cargo_toml:?} workspace")
305+
let rustc_cfg = Builder::new()
306+
.name("ProjectWorkspace::rustc_cfg".to_owned())
307+
.spawn_scoped(s, || {
308+
rustc_cfg::get(toolchain_config, targets.first().map(Deref::deref), extra_env)
314309
})
315-
});
316-
317-
let rustc_dir = s.spawn(|| {
318-
let rustc_dir = match rustc_source {
319-
Some(RustLibSource::Path(path)) => ManifestPath::try_from(path.clone())
320-
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
321-
Some(RustLibSource::Discover) => {
322-
sysroot.discover_rustc_src().ok_or_else(|| {
323-
Some("Failed to discover rustc source for sysroot.".to_owned())
310+
.expect("failed to spawn thread");
311+
let target_data = Builder::new()
312+
.name("ProjectWorkspace::target_data".to_owned())
313+
.spawn_scoped(s, || {
314+
target_data::get(toolchain_config, targets.first().map(Deref::deref), extra_env)
315+
.inspect_err(|e| {
316+
tracing::error!(%e,
317+
"failed fetching data layout for \
318+
{cargo_toml:?} workspace"
319+
)
324320
})
325-
}
326-
None => Err(None),
327-
};
328-
rustc_dir.and_then(|rustc_dir| {
321+
})
322+
.expect("failed to spawn thread");
323+
324+
let rustc_dir = Builder::new()
325+
.name("ProjectWorkspace::rustc_dir".to_owned())
326+
.spawn_scoped(s, || {
327+
let rustc_dir = match rustc_source {
328+
Some(RustLibSource::Path(path)) => ManifestPath::try_from(path.clone())
329+
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
330+
Some(RustLibSource::Discover) => {
331+
sysroot.discover_rustc_src().ok_or_else(|| {
332+
Some("Failed to discover rustc source for sysroot.".to_owned())
333+
})
334+
}
335+
None => Err(None),
336+
};
337+
rustc_dir.and_then(|rustc_dir| {
329338
info!(workspace = %cargo_toml, rustc_dir = %rustc_dir, "Using rustc source");
330339
match FetchMetadata::new(
331340
&rustc_dir,
@@ -359,31 +368,44 @@ impl ProjectWorkspace {
359368
Err(e) => {
360369
tracing::error!(
361370
%e,
362-
"Failed to read Cargo metadata from rustc source at {rustc_dir}",
371+
"Failed to read Cargo metadata from rustc source \
372+
at {rustc_dir}",
363373
);
364374
Err(Some(format!(
365-
"Failed to read Cargo metadata from rustc source at {rustc_dir}: {e}"
375+
"Failed to read Cargo metadata from rustc source \
376+
at {rustc_dir}: {e}"
366377
)))
367378
}
368379
}
369380
})
370-
});
371-
372-
let cargo_metadata = s.spawn(|| fetch_metadata.exec(false, progress));
373-
let loaded_sysroot = s.spawn(|| {
374-
sysroot.load_workspace(
375-
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
376-
config,
377-
workspace_dir,
378-
&targets,
379-
toolchain.clone(),
380-
)),
381-
config.no_deps,
382-
progress,
383-
)
384-
});
385-
let cargo_env =
386-
s.spawn(move || cargo_config_env(cargo_toml, &config_file, &config.extra_env));
381+
})
382+
.expect("failed to spawn thread");
383+
384+
let cargo_metadata = Builder::new()
385+
.name("ProjectWorkspace::cargo_metadata".to_owned())
386+
.spawn_scoped(s, || fetch_metadata.exec(false, progress))
387+
.expect("failed to spawn thread");
388+
let loaded_sysroot = Builder::new()
389+
.name("ProjectWorkspace::loaded_sysroot".to_owned())
390+
.spawn_scoped(s, || {
391+
sysroot.load_workspace(
392+
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
393+
config,
394+
workspace_dir,
395+
&targets,
396+
toolchain.clone(),
397+
)),
398+
config.no_deps,
399+
progress,
400+
)
401+
})
402+
.expect("failed to spawn thread");
403+
let cargo_env = Builder::new()
404+
.name("ProjectWorkspace::cargo_env".to_owned())
405+
.spawn_scoped(s, move || {
406+
cargo_config_env(cargo_toml, &config_file, &config.extra_env)
407+
})
408+
.expect("failed to spawn thread");
387409
thread::Result::Ok((
388410
rustc_cfg.join()?,
389411
target_data.join()?,

crates/rust-analyzer/src/bin/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ fn run_server() -> anyhow::Result<()> {
307307
config.rediscover_workspaces();
308308
}
309309

310+
rayon::ThreadPoolBuilder::new()
311+
.thread_name(|ix| format!("RayonWorker{}", ix))
312+
.build_global()
313+
.unwrap();
314+
310315
// If the io_threads have an error, there's usually an error on the main
311316
// loop too because the channels are closed. Ensure we report both errors.
312317
match (rust_analyzer::main_loop(config, connection), io_threads.join()) {

0 commit comments

Comments
 (0)