Skip to content

Commit fa1bd8c

Browse files
Paolo TranquilliCopilot
andcommitted
Rust: Size the proc-macro server pool from the extraction threads
Parallel extraction workers otherwise all queue on a single proc-macro server. Use up to four server processes, as each loads every proc-macro dylib. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f40adf5 commit fa1bd8c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎rust/extractor/src/config.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use std::path::{Path, PathBuf};
2424

2525
use crate::toolchain::select_toolchain;
2626

27+
const MAX_PROC_MACRO_PROCESSES: usize = 4;
28+
2729
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize, Clone, Copy)]
2830
#[serde(rename_all = "lowercase")]
2931
pub enum Compression {
@@ -203,7 +205,8 @@ impl Config {
203205
}
204206
}
205207

206-
pub fn to_cargo_config(&self, dir: &AbsPath) -> (CargoConfig, LoadCargoConfig) {
208+
/// Builds the rust-analyzer loading configuration for extracting on `threads` threads.
209+
pub fn to_cargo_config(&self, dir: &AbsPath, threads: usize) -> (CargoConfig, LoadCargoConfig) {
207210
let sysroot = self.sysroot(dir);
208211
let mut extra_args = self.cargo_extra_args.clone();
209212
// The fixed toolchain may be older than the project's declared minimum.
@@ -257,7 +260,9 @@ impl Config {
257260
with_proc_macro_server: self.proc_macro_server_choice(dir),
258261
prefill_caches: false,
259262
num_worker_threads: 1,
260-
proc_macro_processes: 1,
263+
// each process serves one expansion at a time and loads every proc-macro dylib,
264+
// so a few processes are shared by all extraction threads to bound memory
265+
proc_macro_processes: threads.clamp(1, MAX_PROC_MACRO_PROCESSES),
261266
},
262267
)
263268
}

‎rust/extractor/src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ fn main() -> anyhow::Result<()> {
365365
let workspaces = extractor.group_files(&manifests, &files);
366366
let cwd = cwd()?;
367367
log_project_toolchain();
368-
let (cargo_config, load_cargo_config) = config.to_cargo_config(&cwd);
369368
let library_mode = if config.extract_dependencies_as_source {
370369
SourceKind::Source
371370
} else {
@@ -379,6 +378,7 @@ fn main() -> anyhow::Result<()> {
379378
let source_files = HashSet::from_iter(files.iter().cloned());
380379
let threads = parallel::extraction_threads();
381380
info!("extraction threads: {threads}");
381+
let (cargo_config, load_cargo_config) = config.to_cargo_config(&cwd, threads);
382382

383383
let mut dependencies = DependencyFiles::default();
384384

0 commit comments

Comments
 (0)