From 7cd6f12926295476d162e21e315ee72671985cd2 Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Fri, 3 Jan 2020 13:59:46 +0100 Subject: Split `crate_def_map` into two methods This change: - introduces `compute_crate_def_map` query and renames `CrateDefMap::crate_def_map_query` for consistency, - annotates `crate_def_map` as `salsa::transparent` and adds a top-level `crate_def_map` wrapper function around that starts the profiler and immediately calls into `compute_crate_def_map` query. This allows us to better understand where we spent the time, in particular, how much is spent in the recomputaiton and how much in salsa. Example output (where we don't actually re-compute anything, but the query still takes a non-trivial amount of time): ``` 211ms - handle_inlay_hints 150ms - get_inlay_hints 150ms - SourceAnalyzer::new 65ms - def_with_body_from_child_node 65ms - analyze_container 65ms - analyze_container 65ms - Module::from_definition 65ms - Module::from_file 65ms - crate_def_map 1ms - parse_macro_query (6 calls) 0ms - raw_items_query (1 calls) 64ms - ??? ``` Signed-off-by: Michal Terepeta --- crates/ra_hir_def/src/db.rs | 11 ++++++++++- crates/ra_hir_def/src/nameres.rs | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index c55fd4111..a348f37bc 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use hir_expand::{db::AstDatabase, HirFileId}; use ra_db::{salsa, CrateId, SourceDatabase}; +use ra_prof::profile; use ra_syntax::SmolStr; use crate::{ @@ -46,9 +47,12 @@ pub trait DefDatabase: InternDatabase + AstDatabase { #[salsa::invoke(RawItems::raw_items_query)] fn raw_items(&self, file_id: HirFileId) -> Arc; - #[salsa::invoke(CrateDefMap::crate_def_map_query)] + #[salsa::transparent] fn crate_def_map(&self, krate: CrateId) -> Arc; + #[salsa::invoke(CrateDefMap::compute_crate_def_map)] + fn compute_crate_def_map(&self, krate: CrateId) -> Arc; + #[salsa::invoke(StructData::struct_data_query)] fn struct_data(&self, id: StructId) -> Arc; #[salsa::invoke(StructData::union_data_query)] @@ -104,3 +108,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase { #[salsa::invoke(Documentation::documentation_query)] fn documentation(&self, def: AttrDefId) -> Option; } + +fn crate_def_map(db: &impl DefDatabase, krate: CrateId) -> Arc { + let _p = profile("crate_def_map"); + db.compute_crate_def_map(krate) +} diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 5d4ca73a3..43255f4a1 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -172,13 +172,13 @@ pub struct ModuleData { } impl CrateDefMap { - pub(crate) fn crate_def_map_query( + pub(crate) fn compute_crate_def_map( // Note that this doesn't have `+ AstDatabase`! // This gurantess that `CrateDefMap` is stable across reparses. db: &impl DefDatabase, krate: CrateId, ) -> Arc { - let _p = profile("crate_def_map_query"); + let _p = profile("compute_crate_def_map"); let def_map = { let crate_graph = db.crate_graph(); let edition = crate_graph.edition(krate); -- cgit v1.2.3 From 2e2e4435605b8fdabb36f018c2d6cba1fd0069b8 Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Fri, 3 Jan 2020 14:20:04 +0100 Subject: Add `_query` suffix to `compute_crate_def_map` for consistency Signed-off-by: Michal Terepeta --- crates/ra_hir_def/src/db.rs | 2 +- crates/ra_hir_def/src/nameres.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index a348f37bc..da273eb11 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -50,7 +50,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase { #[salsa::transparent] fn crate_def_map(&self, krate: CrateId) -> Arc; - #[salsa::invoke(CrateDefMap::compute_crate_def_map)] + #[salsa::invoke(CrateDefMap::compute_crate_def_map_query)] fn compute_crate_def_map(&self, krate: CrateId) -> Arc; #[salsa::invoke(StructData::struct_data_query)] diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 43255f4a1..4d210eab1 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -172,7 +172,7 @@ pub struct ModuleData { } impl CrateDefMap { - pub(crate) fn compute_crate_def_map( + pub(crate) fn compute_crate_def_map_query( // Note that this doesn't have `+ AstDatabase`! // This gurantess that `CrateDefMap` is stable across reparses. db: &impl DefDatabase, -- cgit v1.2.3