mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 03:45:04 +00:00
cleanup + detect num cpus
This commit is contained in:
parent
0b0bfc6fdd
commit
f83c0166be
6 changed files with 13 additions and 38 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -1013,9 +1013,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.0"
|
version = "1.13.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
|
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi",
|
"hermit-abi",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -1349,6 +1349,7 @@ dependencies = [
|
||||||
"lsp-types",
|
"lsp-types",
|
||||||
"mbe",
|
"mbe",
|
||||||
"mimalloc",
|
"mimalloc",
|
||||||
|
"num_cpus",
|
||||||
"oorandom",
|
"oorandom",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"proc_macro_api",
|
"proc_macro_api",
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub use crate::{
|
||||||
moniker::{MonikerKind, MonikerResult, PackageInformation},
|
moniker::{MonikerKind, MonikerResult, PackageInformation},
|
||||||
move_item::Direction,
|
move_item::Direction,
|
||||||
navigation_target::NavigationTarget,
|
navigation_target::NavigationTarget,
|
||||||
prime_caches::{ParallelPrimeCachesProgress, PrimeCachesProgress},
|
prime_caches::ParallelPrimeCachesProgress,
|
||||||
references::ReferenceSearchResult,
|
references::ReferenceSearchResult,
|
||||||
rename::RenameError,
|
rename::RenameError,
|
||||||
runnables::{Runnable, RunnableKind, TestId},
|
runnables::{Runnable, RunnableKind, TestId},
|
||||||
|
@ -244,13 +244,6 @@ impl Analysis {
|
||||||
self.with_db(|db| status::status(&*db, file_id))
|
self.with_db(|db| status::status(&*db, file_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prime_caches<F>(&self, cb: F) -> Cancellable<()>
|
|
||||||
where
|
|
||||||
F: Fn(PrimeCachesProgress) + Sync + std::panic::UnwindSafe,
|
|
||||||
{
|
|
||||||
self.with_db(move |db| prime_caches::prime_caches(db, &cb))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
|
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
|
||||||
where
|
where
|
||||||
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
|
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
|
||||||
|
|
|
@ -16,29 +16,6 @@ use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::RootDatabase;
|
use crate::RootDatabase;
|
||||||
|
|
||||||
/// We started indexing a crate.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PrimeCachesProgress {
|
|
||||||
pub on_crate: String,
|
|
||||||
pub n_done: usize,
|
|
||||||
pub n_total: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) + Sync)) {
|
|
||||||
let _p = profile::span("prime_caches");
|
|
||||||
let graph = db.crate_graph();
|
|
||||||
let to_prime = compute_crates_to_prime(db, &graph);
|
|
||||||
|
|
||||||
let n_total = to_prime.len();
|
|
||||||
for (n_done, &crate_id) in to_prime.iter().enumerate() {
|
|
||||||
let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string();
|
|
||||||
|
|
||||||
cb(PrimeCachesProgress { on_crate: crate_name, n_done, n_total });
|
|
||||||
// This also computes the DefMap
|
|
||||||
db.import_map(crate_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// We're indexing many crates.
|
/// We're indexing many crates.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParallelPrimeCachesProgress {
|
pub struct ParallelPrimeCachesProgress {
|
||||||
|
|
|
@ -31,6 +31,7 @@ serde = { version = "1.0.106", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.48", features = ["preserve_order"] }
|
serde_json = { version = "1.0.48", features = ["preserve_order"] }
|
||||||
threadpool = "1.7.1"
|
threadpool = "1.7.1"
|
||||||
rayon = "1.5"
|
rayon = "1.5"
|
||||||
|
num_cpus = "1.13.1"
|
||||||
mimalloc = { version = "0.1.19", default-features = false, optional = true }
|
mimalloc = { version = "0.1.19", default-features = false, optional = true }
|
||||||
lsp-server = "0.5.1"
|
lsp-server = "0.5.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub fn load_workspace(
|
||||||
load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver);
|
load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver);
|
||||||
|
|
||||||
if load_config.prefill_caches {
|
if load_config.prefill_caches {
|
||||||
host.analysis().prime_caches(|_| {})?;
|
host.analysis().parallel_prime_caches(1, |_| {})?;
|
||||||
}
|
}
|
||||||
Ok((host, vfs, proc_macro_client))
|
Ok((host, vfs, proc_macro_client))
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,10 +509,13 @@ impl GlobalState {
|
||||||
let analysis = self.snapshot().analysis;
|
let analysis = self.snapshot().analysis;
|
||||||
move |sender| {
|
move |sender| {
|
||||||
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
|
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
|
||||||
let res = analysis.parallel_prime_caches(32, |progress| {
|
let res = analysis.parallel_prime_caches(
|
||||||
let report = PrimeCachesProgress::Report(progress);
|
num_cpus::get_physical().try_into().unwrap_or(u8::MAX),
|
||||||
sender.send(Task::PrimeCaches(report)).unwrap();
|
|progress| {
|
||||||
});
|
let report = PrimeCachesProgress::Report(progress);
|
||||||
|
sender.send(Task::PrimeCaches(report)).unwrap();
|
||||||
|
},
|
||||||
|
);
|
||||||
sender
|
sender
|
||||||
.send(Task::PrimeCaches(PrimeCachesProgress::End {
|
.send(Task::PrimeCaches(PrimeCachesProgress::End {
|
||||||
cancelled: res.is_err(),
|
cancelled: res.is_err(),
|
||||||
|
|
Loading…
Reference in a new issue