mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Allow choosing logical cores for num threads config
This commit is contained in:
parent
913371fb0b
commit
e972dd2385
3 changed files with 43 additions and 9 deletions
|
@ -29,7 +29,7 @@ pub struct ParallelPrimeCachesProgress {
|
||||||
|
|
||||||
pub fn parallel_prime_caches(
|
pub fn parallel_prime_caches(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
num_worker_threads: u8,
|
num_worker_threads: usize,
|
||||||
cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync),
|
cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync),
|
||||||
) {
|
) {
|
||||||
let _p = tracing::info_span!("parallel_prime_caches").entered();
|
let _p = tracing::info_span!("parallel_prime_caches").entered();
|
||||||
|
|
|
@ -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
|
where
|
||||||
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
|
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,7 +73,7 @@ config_data! {
|
||||||
/// Warm up caches on project load.
|
/// Warm up caches on project load.
|
||||||
cachePriming_enable: bool = true,
|
cachePriming_enable: bool = true,
|
||||||
/// How many worker threads to handle priming caches. The default `0` means to pick automatically.
|
/// 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.
|
/// Pass `--all-targets` to cargo invocation.
|
||||||
cargo_allTargets: bool = true,
|
cargo_allTargets: bool = true,
|
||||||
|
@ -583,7 +583,7 @@ config_data! {
|
||||||
notifications_unindexedProject: bool = false,
|
notifications_unindexedProject: bool = false,
|
||||||
|
|
||||||
/// How many worker threads in the main loop. The default `null` means to pick automatically.
|
/// 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.
|
/// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.
|
||||||
procMacro_attributes_enable: bool = true,
|
procMacro_attributes_enable: bool = true,
|
||||||
|
@ -2095,15 +2095,22 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prime_caches_num_threads(&self) -> u8 {
|
pub fn prime_caches_num_threads(&self) -> usize {
|
||||||
match *self.cachePriming_numThreads() {
|
match self.cachePriming_numThreads() {
|
||||||
0 => num_cpus::get_physical().try_into().unwrap_or(u8::MAX),
|
NumThreads::Concrete(0) | NumThreads::Physical => num_cpus::get_physical(),
|
||||||
n => n,
|
&NumThreads::Concrete(n) => n,
|
||||||
|
NumThreads::Logical => num_cpus::get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_loop_num_threads(&self) -> usize {
|
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 {
|
pub fn typing_autoclose_angle(&self) -> bool {
|
||||||
|
@ -2524,6 +2531,15 @@ pub enum TargetDirectory {
|
||||||
Directory(Utf8PathBuf),
|
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 {
|
macro_rules! _default_val {
|
||||||
(@verbatim: $s:literal, $ty:ty) => {{
|
(@verbatim: $s:literal, $ty:ty) => {{
|
||||||
let default_: $ty = serde_json::from_str(&$s).unwrap();
|
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}"),
|
_ => panic!("missing entry for {ty}: {default}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue