Skip to content

Commit

Permalink
Merge #9208
Browse files Browse the repository at this point in the history
9208: minor: Populate import maps eagerly to speed up flyimports r=SomeoneToIgnore a=SomeoneToIgnore

Part of #7542
Follow up of #9206 (comment)
Reduces `import_on_the_fly @ sel` case in the `integrated_completion_benchmark` by ~300ms.


Also enables cache priming for manual workspace loading to reflect the results in the benchmarks.

Before:
<img width="1198" alt="image" src="https://user-images.githubusercontent.com/2690773/121606148-4a734a80-ca56-11eb-812a-7955e93817f1.png">


After:
<img width="1200" alt="image" src="https://user-images.githubusercontent.com/2690773/121606156-4e06d180-ca56-11eb-891b-1ed878b53d7e.png">


Co-authored-by: Kirill Bulatov <[email protected]>
  • Loading branch information
bors[bot] and SomeoneToIgnore authored Jun 11, 2021
2 parents c4c1fcb + 3394481 commit c62ec3d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
7 changes: 4 additions & 3 deletions crates/ide/src/prime_caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress)
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.
// Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
// cancellation, so we cannot use rayon.
for (i, krate) in topo.iter().enumerate() {
let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string();
for (i, &crate_id) in topo.iter().enumerate() {
let crate_name = graph[crate_id].display_name.as_deref().unwrap_or_default().to_string();

cb(PrimeCachesProgress::StartedOnCrate {
on_crate: crate_name,
n_done: i,
n_total: topo.len(),
});
db.crate_def_map(*krate);
db.crate_def_map(crate_id);
db.import_map(crate_id);
}
}
1 change: 0 additions & 1 deletion crates/rust-analyzer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use vfs::Vfs;
pub use self::{
analysis_stats::AnalysisStatsCmd,
diagnostics::diagnostics,
load_cargo::{load_workspace, load_workspace_at, LoadCargoConfig},
ssr::{apply_ssr_rules, search_for_patterns},
};

Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl AnalysisStatsCmd {
load_out_dirs_from_check: self.enable_build_scripts,
wrap_rustc: false,
with_proc_macro: self.enable_proc_macros,
prefill_caches: false,
};
let (host, vfs, _proc_macro) =
load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?;
Expand Down
8 changes: 6 additions & 2 deletions crates/rust-analyzer/src/cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ pub fn diagnostics(
with_proc_macro: bool,
) -> Result<()> {
let cargo_config = Default::default();
let load_cargo_config =
LoadCargoConfig { load_out_dirs_from_check, with_proc_macro, wrap_rustc: false };
let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check,
with_proc_macro,
wrap_rustc: false,
prefill_caches: false,
};
let (host, _vfs, _proc_macro) =
load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?;
let db = host.raw_database();
Expand Down
18 changes: 12 additions & 6 deletions crates/rust-analyzer/src/cli/load_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ use vfs::{loader::Handle, AbsPath, AbsPathBuf};

use crate::reload::{ProjectFolders, SourceRootConfig};

pub struct LoadCargoConfig {
pub load_out_dirs_from_check: bool,
pub wrap_rustc: bool,
pub with_proc_macro: bool,
pub(crate) struct LoadCargoConfig {
pub(crate) load_out_dirs_from_check: bool,
pub(crate) wrap_rustc: bool,
pub(crate) with_proc_macro: bool,
pub(crate) prefill_caches: bool,
}

pub fn load_workspace_at(
pub(crate) fn load_workspace_at(
root: &Path,
cargo_config: &CargoConfig,
load_config: &LoadCargoConfig,
Expand All @@ -33,7 +34,7 @@ pub fn load_workspace_at(
load_workspace(workspace, load_config, progress)
}

pub fn load_workspace(
fn load_workspace(
ws: ProjectWorkspace,
config: &LoadCargoConfig,
progress: &dyn Fn(String),
Expand Down Expand Up @@ -82,6 +83,10 @@ pub fn load_workspace(
log::debug!("crate graph: {:?}", crate_graph);
let host =
load_crate_graph(crate_graph, project_folders.source_root_config, &mut vfs, &receiver);

if config.prefill_caches {
host.analysis().prime_caches(|_| {})?;
}
Ok((host, vfs, proc_macro_client))
}

Expand Down Expand Up @@ -144,6 +149,7 @@ mod tests {
load_out_dirs_from_check: false,
wrap_rustc: false,
with_proc_macro: false,
prefill_caches: false,
};
let (host, _vfs, _proc_macro) =
load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?;
Expand Down
9 changes: 7 additions & 2 deletions crates/rust-analyzer/src/cli/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> {
load_out_dirs_from_check: true,
wrap_rustc: false,
with_proc_macro: true,
prefill_caches: false,
};
let (host, vfs, _proc_macro) =
load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?;
Expand All @@ -39,8 +40,12 @@ pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<Stri
use ide_db::base_db::SourceDatabaseExt;
use ide_db::symbol_index::SymbolsDatabase;
let cargo_config = Default::default();
let load_cargo_config =
LoadCargoConfig { load_out_dirs_from_check: true, wrap_rustc: true, with_proc_macro: true };
let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: true,
wrap_rustc: true,
with_proc_macro: true,
prefill_caches: false,
};
let (host, _vfs, _proc_macro) =
load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?;
let db = host.raw_database();
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/integrated_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn integrated_highlighting_benchmark() {
load_out_dirs_from_check: true,
wrap_rustc: false,
with_proc_macro: false,
prefill_caches: false,
};

let (mut host, vfs, _proc_macro) = {
Expand Down Expand Up @@ -91,6 +92,7 @@ fn integrated_completion_benchmark() {
load_out_dirs_from_check: true,
wrap_rustc: false,
with_proc_macro: false,
prefill_caches: true,
};

let (mut host, vfs, _proc_macro) = {
Expand Down

0 comments on commit c62ec3d

Please sign in to comment.