mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-12 20:00:31 +00:00
optimize pick_process to short circuit and return as early as possible if a valid process is found
This commit is contained in:
parent
d0c00b5c80
commit
deee719d6b
@ -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(
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user