Skip to content

Commit f83c016

Browse files
committed
cleanup + detect num cpus
1 parent 0b0bfc6 commit f83c016

File tree

6 files changed

+13
-38
lines changed

6 files changed

+13
-38
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub use crate::{
8787
moniker::{MonikerKind, MonikerResult, PackageInformation},
8888
move_item::Direction,
8989
navigation_target::NavigationTarget,
90-
prime_caches::{ParallelPrimeCachesProgress, PrimeCachesProgress},
90+
prime_caches::ParallelPrimeCachesProgress,
9191
references::ReferenceSearchResult,
9292
rename::RenameError,
9393
runnables::{Runnable, RunnableKind, TestId},
@@ -244,13 +244,6 @@ impl Analysis {
244244
self.with_db(|db| status::status(&*db, file_id))
245245
}
246246

247-
pub fn prime_caches<F>(&self, cb: F) -> Cancellable<()>
248-
where
249-
F: Fn(PrimeCachesProgress) + Sync + std::panic::UnwindSafe,
250-
{
251-
self.with_db(move |db| prime_caches::prime_caches(db, &cb))
252-
}
253-
254247
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
255248
where
256249
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,

crates/ide/src/prime_caches.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ use rustc_hash::FxHashSet;
1616

1717
use crate::RootDatabase;
1818

19-
/// We started indexing a crate.
20-
#[derive(Debug)]
21-
pub struct PrimeCachesProgress {
22-
pub on_crate: String,
23-
pub n_done: usize,
24-
pub n_total: usize,
25-
}
26-
27-
pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) + Sync)) {
28-
let _p = profile::span("prime_caches");
29-
let graph = db.crate_graph();
30-
let to_prime = compute_crates_to_prime(db, &graph);
31-
32-
let n_total = to_prime.len();
33-
for (n_done, &crate_id) in to_prime.iter().enumerate() {
34-
let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string();
35-
36-
cb(PrimeCachesProgress { on_crate: crate_name, n_done, n_total });
37-
// This also computes the DefMap
38-
db.import_map(crate_id);
39-
}
40-
}
41-
4219
/// We're indexing many crates.
4320
#[derive(Debug)]
4421
pub struct ParallelPrimeCachesProgress {

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ serde = { version = "1.0.106", features = ["derive"] }
3131
serde_json = { version = "1.0.48", features = ["preserve_order"] }
3232
threadpool = "1.7.1"
3333
rayon = "1.5"
34+
num_cpus = "1.13.1"
3435
mimalloc = { version = "0.1.19", default-features = false, optional = true }
3536
lsp-server = "0.5.1"
3637
tracing = "0.1"

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn load_workspace(
8888
load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver);
8989

9090
if load_config.prefill_caches {
91-
host.analysis().prime_caches(|_| {})?;
91+
host.analysis().parallel_prime_caches(1, |_| {})?;
9292
}
9393
Ok((host, vfs, proc_macro_client))
9494
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,13 @@ impl GlobalState {
509509
let analysis = self.snapshot().analysis;
510510
move |sender| {
511511
sender.send(Task::PrimeCaches(PrimeCachesProgress::Begin)).unwrap();
512-
let res = analysis.parallel_prime_caches(32, |progress| {
513-
let report = PrimeCachesProgress::Report(progress);
514-
sender.send(Task::PrimeCaches(report)).unwrap();
515-
});
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+
);
516519
sender
517520
.send(Task::PrimeCaches(PrimeCachesProgress::End {
518521
cancelled: res.is_err(),

0 commit comments

Comments
 (0)