Unnamed repository; edit this file 'description' to name the repository.
Allow choosing logical cores for num threads config
Lukas Wirth 2024-06-09
parent 913371f · commit e972dd2
-rw-r--r--crates/ide-db/src/prime_caches.rs2
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs48
3 files changed, 43 insertions, 9 deletions
diff --git a/crates/ide-db/src/prime_caches.rs b/crates/ide-db/src/prime_caches.rs
index 1ca5206011..b4486d1502 100644
--- a/crates/ide-db/src/prime_caches.rs
+++ b/crates/ide-db/src/prime_caches.rs
@@ -29,7 +29,7 @@ pub struct ParallelPrimeCachesProgress {
pub fn parallel_prime_caches(
db: &RootDatabase,
- num_worker_threads: u8,
+ num_worker_threads: usize,
cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync),
) {
let _p = tracing::info_span!("parallel_prime_caches").entered();
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index e9408bf897..a2ac62341d 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -284,7 +284,7 @@ impl Analysis {
})
}
- pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
+ pub fn parallel_prime_caches<F>(&self, num_worker_threads: usize, cb: F) -> Cancellable<()>
where
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
{
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 497fd67e92..98686f2cd5 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -73,7 +73,7 @@ config_data! {
/// Warm up caches on project load.
cachePriming_enable: bool = true,
/// How many worker threads to handle priming caches. The default `0` means to pick automatically.
- cachePriming_numThreads: ParallelCachePrimingNumThreads = 0u8,
+ cachePriming_numThreads: NumThreads = NumThreads::Physical,
/// Pass `--all-targets` to cargo invocation.
cargo_allTargets: bool = true,
@@ -583,7 +583,7 @@ config_data! {
notifications_unindexedProject: bool = false,
/// How many worker threads in the main loop. The default `null` means to pick automatically.
- numThreads: Option<usize> = None,
+ numThreads: Option<NumThreads> = None,
/// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.
procMacro_attributes_enable: bool = true,
@@ -2095,15 +2095,22 @@ impl Config {
}
}
- pub fn prime_caches_num_threads(&self) -> u8 {
- match *self.cachePriming_numThreads() {
- 0 => num_cpus::get_physical().try_into().unwrap_or(u8::MAX),
- n => n,
+ pub fn prime_caches_num_threads(&self) -> usize {
+ match self.cachePriming_numThreads() {
+ NumThreads::Concrete(0) | NumThreads::Physical => num_cpus::get_physical(),
+ &NumThreads::Concrete(n) => n,
+ NumThreads::Logical => num_cpus::get(),
}
}
pub fn main_loop_num_threads(&self) -> usize {
- self.numThreads().unwrap_or(num_cpus::get_physical())
+ match self.numThreads() {
+ Some(NumThreads::Concrete(0)) | None | Some(NumThreads::Physical) => {
+ num_cpus::get_physical()
+ }
+ &Some(NumThreads::Concrete(n)) => n,
+ Some(NumThreads::Logical) => num_cpus::get(),
+ }
}
pub fn typing_autoclose_angle(&self) -> bool {
@@ -2524,6 +2531,15 @@ pub enum TargetDirectory {
Directory(Utf8PathBuf),
}
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+#[serde(rename_all = "snake_case")]
+#[serde(untagged)]
+pub enum NumThreads {
+ Physical,
+ Logical,
+ Concrete(usize),
+}
+
macro_rules! _default_val {
(@verbatim: $s:literal, $ty:ty) => {{
let default_: $ty = serde_json::from_str(&$s).unwrap();
@@ -3260,6 +3276,24 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
},
],
},
+ "Option<NumThreads>" => set! {
+ "anyOf": [
+ {
+ "type": "null"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "string",
+ "enum": ["physical", "logical", ],
+ "enumDescriptions": [
+ "Use the number of physical cores",
+ "Use the number of logical cores",
+ ],
+ },
+ ],
+ },
_ => panic!("missing entry for {ty}: {default}"),
}