Skip to content

Commit 25f67b6

Browse files
committed
make it a config
1 parent bcc9909 commit 25f67b6

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

crates/ide/src/prime_caches.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ pub(crate) fn parallel_prime_caches(
108108
}
109109

110110
// recv_timeout is somewhat a hack, we need a way to from this thread check to see if the current salsa revision
111-
// is cancelled.
111+
// is cancelled on a regular basis. workers will only exit if they are processing a task that is cancelled, or
112+
// if this thread exits, and closes the work channel.
112113
let worker_progress = match progress_receiver.recv_timeout(Duration::from_millis(10)) {
113114
Ok(p) => p,
114115
Err(crossbeam_channel::RecvTimeoutError::Timeout) => {

crates/ide/src/prime_caches/topologic_sort.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! helper data structure to schedule work for parallel prime caches.
12
use std::{collections::VecDeque, hash::Hash};
23

34
use rustc_hash::FxHashMap;

crates/rust-analyzer/src/config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ config_data! {
298298
/// Whether to show `can't find Cargo.toml` error message.
299299
notifications_cargoTomlNotFound: bool = "true",
300300

301+
/// How many worker threads to to handle priming caches. The default `0` means to pick automatically.
302+
primeCaches_numThreads: ParallelPrimeCachesNumThreads = "0",
303+
301304
/// Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.
302305
procMacro_enable: bool = "true",
303306
/// Internal config, path to proc-macro server executable (typically,
@@ -1016,6 +1019,13 @@ impl Config {
10161019
yield_points: self.data.highlightRelated_yieldPoints,
10171020
}
10181021
}
1022+
1023+
pub fn prime_caches_num_threads(&self) -> u8 {
1024+
match self.data.primeCaches_numThreads {
1025+
0 => num_cpus::get_physical().try_into().unwrap_or(u8::MAX),
1026+
n => n,
1027+
}
1028+
}
10191029
}
10201030

10211031
#[derive(Deserialize, Debug, Clone, Copy)]
@@ -1130,6 +1140,8 @@ enum WorkspaceSymbolSearchKindDef {
11301140
AllSymbols,
11311141
}
11321142

1143+
type ParallelPrimeCachesNumThreads = u8;
1144+
11331145
macro_rules! _config_data {
11341146
(struct $name:ident {
11351147
$(
@@ -1351,6 +1363,11 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
13511363
"Search for all symbols kinds"
13521364
],
13531365
},
1366+
"ParallelPrimeCachesNumThreads" => set! {
1367+
"type": "number",
1368+
"minimum": 0,
1369+
"maximum": 255
1370+
},
13541371
_ => panic!("{}: {}", ty, default),
13551372
}
13561373

crates/rust-analyzer/src/main_loop.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,16 @@ impl GlobalState {
505505
self.fetch_build_data();
506506
}
507507
if self.prime_caches_queue.should_start_op() {
508+
let num_worker_threads = self.config.prime_caches_num_threads();
509+
508510
self.task_pool.handle.spawn_with_sender({
509511
let analysis = self.snapshot().analysis;
510512
move |sender| {
511513
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
512-
let res = analysis.parallel_prime_caches(
513-
num_cpus::get_physical().try_into().unwrap_or(u8::MAX),
514-
|progress| {
515-
let report = PrimeCachesProgress::Report(progress);
516-
sender.send(Task::PrimeCaches(report)).unwrap();
517-
},
518-
);
514+
let res = analysis.parallel_prime_caches(num_worker_threads, |progress| {
515+
let report = PrimeCachesProgress::Report(progress);
516+
sender.send(Task::PrimeCaches(report)).unwrap();
517+
});
519518
sender
520519
.send(Task::PrimeCaches(PrimeCachesProgress::End {
521520
cancelled: res.is_err(),

docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
454454
--
455455
Whether to show `can't find Cargo.toml` error message.
456456
--
457+
[[rust-analyzer.primeCaches.numThreads]]rust-analyzer.primeCaches.numThreads (default: `0`)::
458+
+
459+
--
460+
How many worker threads to to handle priming caches. The default `0` means to pick automatically.
461+
--
457462
[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `true`)::
458463
+
459464
--

editors/code/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@
880880
"default": true,
881881
"type": "boolean"
882882
},
883+
"rust-analyzer.primeCaches.numThreads": {
884+
"markdownDescription": "How many worker threads to to handle priming caches. The default `0` means to pick automatically.",
885+
"default": 0,
886+
"type": "number",
887+
"minimum": 0,
888+
"maximum": 255
889+
},
883890
"rust-analyzer.procMacro.enable": {
884891
"markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.",
885892
"default": true,

0 commit comments

Comments
 (0)