Skip to content

Commit 09d33f3

Browse files
committed
Add diagnostics integrated benchmark
1 parent a3b6e89 commit 09d33f3

File tree

4 files changed

+94
-46
lines changed

4 files changed

+94
-46
lines changed

crates/base-db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait Upcast<T: ?Sized> {
4343
}
4444

4545
pub const DEFAULT_PARSE_LRU_CAP: usize = 128;
46-
pub const DEFAULT_BORROWCK_LRU_CAP: usize = 256;
46+
pub const DEFAULT_BORROWCK_LRU_CAP: usize = 1024;
4747

4848
pub trait FileLoader {
4949
/// Text of the file.

crates/rust-analyzer/src/integrated_benchmarks.rs

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
//! which you can use to paste the command in terminal and add `--release` manually.
1212
1313
use hir::ChangeWithProcMacros;
14-
use ide::{AnalysisHost, CallableSnippets, CompletionConfig, FilePosition, TextSize};
14+
use ide::{
15+
AnalysisHost, CallableSnippets, CompletionConfig, DiagnosticsConfig, FilePosition, TextSize,
16+
};
1517
use ide_db::{
1618
imports::insert_use::{ImportGranularity, InsertUseConfig},
1719
SnippetCap,
@@ -157,7 +159,7 @@ fn integrated_completion_benchmark() {
157159
analysis.completions(&config, position, None).unwrap();
158160
}
159161

160-
crate::tracing::hprof::init("*>5");
162+
let _g = crate::tracing::hprof::init("*");
161163

162164
let completion_offset = {
163165
let _it = stdx::timeit("change");
@@ -244,6 +246,80 @@ fn integrated_completion_benchmark() {
244246
}
245247
}
246248

249+
#[test]
250+
fn integrated_diagnostics_benchmark() {
251+
if std::env::var("RUN_SLOW_BENCHES").is_err() {
252+
return;
253+
}
254+
255+
// Load rust-analyzer itself.
256+
let workspace_to_load = project_root();
257+
let file = "./crates/hir/src/lib.rs";
258+
259+
let cargo_config = CargoConfig {
260+
sysroot: Some(project_model::RustLibSource::Discover),
261+
..CargoConfig::default()
262+
};
263+
let load_cargo_config = LoadCargoConfig {
264+
load_out_dirs_from_check: true,
265+
with_proc_macro_server: ProcMacroServerChoice::None,
266+
prefill_caches: true,
267+
};
268+
269+
let (db, vfs, _proc_macro) = {
270+
let _it = stdx::timeit("workspace loading");
271+
load_workspace_at(&workspace_to_load, &cargo_config, &load_cargo_config, &|_| {}).unwrap()
272+
};
273+
let mut host = AnalysisHost::with_database(db);
274+
275+
let file_id = {
276+
let file = workspace_to_load.join(file);
277+
let path = VfsPath::from(AbsPathBuf::assert(file));
278+
vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {path}"))
279+
};
280+
281+
let diagnostics_config = DiagnosticsConfig {
282+
enabled: false,
283+
proc_macros_enabled: true,
284+
proc_attr_macros_enabled: true,
285+
disable_experimental: true,
286+
disabled: Default::default(),
287+
expr_fill_default: Default::default(),
288+
style_lints: false,
289+
insert_use: InsertUseConfig {
290+
granularity: ImportGranularity::Crate,
291+
enforce_granularity: false,
292+
prefix_kind: hir::PrefixKind::ByCrate,
293+
group: true,
294+
skip_glob_imports: true,
295+
},
296+
prefer_no_std: false,
297+
prefer_prelude: false,
298+
};
299+
host.analysis()
300+
.diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id)
301+
.unwrap();
302+
303+
let _g = crate::tracing::hprof::init("*>1");
304+
305+
{
306+
let _it = stdx::timeit("change");
307+
let mut text = host.analysis().file_text(file_id).unwrap().to_string();
308+
patch(&mut text, "db.struct_data(self.id)", "();\ndb.struct_data(self.id)");
309+
let mut change = ChangeWithProcMacros::new();
310+
change.change_file(file_id, Some(Arc::from(text)));
311+
host.apply_change(change);
312+
};
313+
314+
{
315+
let _p = tracing::span!(tracing::Level::INFO, "diagnostics").entered();
316+
let _span = profile::cpu_span();
317+
host.analysis()
318+
.diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id)
319+
.unwrap();
320+
}
321+
}
322+
247323
fn patch(what: &mut String, from: &str, to: &str) -> usize {
248324
let idx = what.find(from).unwrap();
249325
*what = what.replacen(from, to, 1);

crates/rust-analyzer/src/tracing/config.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ use std::io;
66
use anyhow::Context;
77
use tracing::{level_filters::LevelFilter, Level};
88
use tracing_subscriber::{
9-
filter::{self, Targets},
10-
fmt::{format::FmtSpan, MakeWriter},
11-
layer::SubscriberExt,
12-
util::SubscriberInitExt,
13-
Layer, Registry,
9+
filter::Targets, fmt::MakeWriter, layer::SubscriberExt, util::SubscriberInitExt, Layer,
10+
Registry,
1411
};
1512
use tracing_tree::HierarchicalLayer;
1613

@@ -50,10 +47,7 @@ where
5047

5148
let writer = self.writer;
5249

53-
let ra_fmt_layer = tracing_subscriber::fmt::layer()
54-
.with_span_events(FmtSpan::CLOSE)
55-
.with_writer(writer)
56-
.with_filter(filter);
50+
let ra_fmt_layer = tracing_subscriber::fmt::layer().with_writer(writer).with_filter(filter);
5751

5852
let mut chalk_layer = None;
5953
if let Some(chalk_filter) = self.chalk_filter {
@@ -74,32 +68,7 @@ where
7468
);
7569
};
7670

77-
let mut profiler_layer = None;
78-
if let Some(spec) = self.profile_filter {
79-
let (write_filter, allowed_names) = hprof::WriteFilter::from_spec(&spec);
80-
81-
// this filter the first pass for `tracing`: these are all the "profiling" spans, but things like
82-
// span depth or duration are not filtered here: that only occurs at write time.
83-
let profile_filter = filter::filter_fn(move |metadata| {
84-
let allowed = match &allowed_names {
85-
Some(names) => names.contains(metadata.name()),
86-
None => true,
87-
};
88-
89-
metadata.is_span()
90-
&& allowed
91-
&& metadata.level() >= &Level::INFO
92-
&& !metadata.target().starts_with("salsa")
93-
&& !metadata.target().starts_with("chalk")
94-
});
95-
96-
let layer = hprof::SpanTree::default()
97-
.aggregate(true)
98-
.spec_filter(write_filter)
99-
.with_filter(profile_filter);
100-
101-
profiler_layer = Some(layer);
102-
}
71+
let profiler_layer = self.profile_filter.map(|spec| hprof::layer(&spec));
10372

10473
Registry::default().with(ra_fmt_layer).with(chalk_layer).with(profiler_layer).try_init()?;
10574

crates/rust-analyzer/src/tracing/hprof.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ use tracing_subscriber::{
5353
use crate::tracing::hprof;
5454

5555
pub fn init(spec: &str) -> tracing::subscriber::DefaultGuard {
56+
let subscriber = Registry::default().with(layer(spec));
57+
tracing::subscriber::set_default(subscriber)
58+
}
59+
60+
pub fn layer<S>(spec: &str) -> impl Layer<S>
61+
where
62+
S: Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
63+
{
5664
let (write_filter, allowed_names) = WriteFilter::from_spec(spec);
5765

5866
// this filter the first pass for `tracing`: these are all the "profiling" spans, but things like
@@ -66,17 +74,12 @@ pub fn init(spec: &str) -> tracing::subscriber::DefaultGuard {
6674
metadata.is_span()
6775
&& allowed
6876
&& metadata.level() >= &Level::INFO
69-
&& !metadata.target().starts_with("salsa")
77+
// && !metadata.target().starts_with("salsa")
78+
&& !metadata.target().contains("compute_exhaustiveness_and_usefulness")
7079
&& !metadata.target().starts_with("chalk")
7180
});
7281

73-
let layer = hprof::SpanTree::default()
74-
.aggregate(true)
75-
.spec_filter(write_filter)
76-
.with_filter(profile_filter);
77-
78-
let subscriber = Registry::default().with(layer);
79-
tracing::subscriber::set_default(subscriber)
82+
hprof::SpanTree::default().aggregate(true).spec_filter(write_filter).with_filter(profile_filter)
8083
}
8184

8285
#[derive(Default, Debug)]

0 commit comments

Comments
 (0)