Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rustc-hash = "1.1.0"
serde = { version = "1.0.106", features = ["derive"] }
serde_json = "1.0.48"
threadpool = "1.7.1"
rayon = "1.3.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seeing rayon in Cargo.toml creates an impression of speed 👍 !


stdx = { path = "../stdx" }

Expand Down
13 changes: 10 additions & 3 deletions crates/rust-analyzer/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) enum Command {
},
Stats {
randomize: bool,
parallel: bool,
memory_usage: bool,
only: Option<String>,
with_deps: bool,
Expand Down Expand Up @@ -157,10 +158,14 @@ USAGE:
rust-analyzer analysis-stats [FLAGS] [OPTIONS] [PATH]

FLAGS:
-o, --only Only analyze items matching this path
-h, --help Prints help information
--memory-usage
--memory-usage Collect memory usage statistics (requires `--feature jemalloc`)
--randomize Randomize order in which crates, modules, and items are processed
--parallel Run type inference in parallel
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
--with-deps Also analyze all dependencies
-v, --verbose
-q, --quiet

Expand All @@ -174,6 +179,7 @@ ARGS:
}

let randomize = matches.contains("--randomize");
let parallel = matches.contains("--parallel");
let memory_usage = matches.contains("--memory-usage");
let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
let with_deps: bool = matches.contains("--with-deps");
Expand All @@ -189,6 +195,7 @@ ARGS:

Command::Stats {
randomize,
parallel,
memory_usage,
only,
with_deps,
Expand All @@ -209,7 +216,7 @@ USAGE:
FLAGS:
-h, --help Prints help information
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
-v, --verbose

OPTIONS:
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() -> Result<()> {
args::Command::Highlight { rainbow } => cli::highlight(rainbow)?,
args::Command::Stats {
randomize,
parallel,
memory_usage,
only,
with_deps,
Expand All @@ -45,6 +46,7 @@ fn main() -> Result<()> {
only.as_ref().map(String::as_ref),
with_deps,
randomize,
parallel,
load_output_dirs,
with_proc_macro,
)?,
Expand Down
31 changes: 29 additions & 2 deletions crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{path::Path, time::Instant};

use itertools::Itertools;
use rand::{seq::SliceRandom, thread_rng};
use rayon::prelude::*;
use rustc_hash::FxHashSet;

use hir::{
Expand All @@ -13,19 +14,31 @@ use hir::{
};
use hir_def::FunctionId;
use hir_ty::{Ty, TypeWalk};
use ra_db::SourceDatabaseExt;
use ra_db::{
salsa::{self, ParallelDatabase},
SourceDatabaseExt,
};
use ra_syntax::AstNode;
use stdx::format_to;

use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity};

/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
struct Snap<DB>(DB);
impl<DB: ParallelDatabase> Clone for Snap<salsa::Snapshot<DB>> {
fn clone(&self) -> Snap<salsa::Snapshot<DB>> {
Snap(self.0.snapshot())
}
}

pub fn analysis_stats(
verbosity: Verbosity,
memory_usage: bool,
path: &Path,
only: Option<&str>,
with_deps: bool,
randomize: bool,
parallel: bool,
load_output_dirs: bool,
with_proc_macro: bool,
) -> Result<()> {
Expand Down Expand Up @@ -91,12 +104,26 @@ pub fn analysis_stats(
funcs.shuffle(&mut thread_rng());
}

let inference_time = Instant::now();
let mut bar = match verbosity {
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
_ => ProgressReport::new(funcs.len() as u64),
};

if parallel {
let inference_time = Instant::now();
let snap = Snap(db.snapshot());
funcs
.par_iter()
.map_with(snap, |snap, &f| {
let f_id = FunctionId::from(f);
snap.0.body(f_id.into());
snap.0.infer(f_id.into());
})
.count();
println!("Parallel Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage());
}

let inference_time = Instant::now();
bar.tick();
let mut num_exprs = 0;
let mut num_exprs_unknown = 0;
Expand Down