optimize pick_process to short circuit and return as early as possible if a valid process is found

This commit is contained in:
bit-aloo 2026-01-05 09:56:02 +05:30
parent d0c00b5c80
commit deee719d6b
No known key found for this signature in database
2 changed files with 21 additions and 9 deletions

View File

@ -28,14 +28,26 @@ impl ProcMacroServerPool {
}
pub(crate) fn pick_process(&self) -> Result<&ProcMacroServerProcess, ServerError> {
self.workers
.iter()
.filter(|w| w.exited().is_none())
.min_by_key(|w| w.number_of_active_req())
.ok_or_else(|| ServerError {
message: "all proc-macro server workers have exited".into(),
io: None,
})
let mut best: Option<&ProcMacroServerProcess> = None;
let mut best_load = u32::MAX;
for w in self.workers.iter().filter(|w| w.exited().is_none()) {
let load = w.number_of_active_req();
if load == 0 {
return Ok(w);
}
if load < best_load {
best = Some(w);
best_load = load;
}
}
best.ok_or_else(|| ServerError {
message: "all proc-macro server workers have exited".into(),
io: None,
})
}
pub(crate) fn load_dylib(

View File

@ -380,7 +380,7 @@ config_data! {
/// The number of worker threads in the main loop. The default `null` means to pick
/// automatically.
numThreads: Option<NumThreads> = None,
/// The number of proc-macro-srv processes
/// The number of proc-macro-srv processes
proc_macro_processes: NumProcesses = NumProcesses::Concrete(1),
/// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.