2731: Split `crate_def_map` into two methods r=matklad a=michalt

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 <michal.terepeta@gmail.com>

Co-authored-by: Michal Terepeta <michal.terepeta@gmail.com>
This commit is contained in:
bors[bot] 2020-01-03 13:25:37 +00:00 committed by GitHub
commit 15d94cbffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -1,11 +1,11 @@
//! FIXME: write short doc here
pub use hir_def::db::{
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery,
TraitDataQuery, TypeAliasDataQuery,
BodyQuery, BodyWithSourceMapQuery, ComputeCrateDefMapQuery, ConstDataQuery,
CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery,
ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase,
InternDatabaseStorage, LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery,
StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
};
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,

View File

@ -3,6 +3,7 @@
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<RawItems>;
#[salsa::invoke(CrateDefMap::crate_def_map_query)]
#[salsa::transparent]
fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
#[salsa::invoke(CrateDefMap::compute_crate_def_map_query)]
fn compute_crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
#[salsa::invoke(StructData::struct_data_query)]
fn struct_data(&self, id: StructId) -> Arc<StructData>;
#[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<Documentation>;
}
fn crate_def_map(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
let _p = profile("crate_def_map");
db.compute_crate_def_map(krate)
}

View File

@ -172,13 +172,13 @@ pub struct ModuleData {
}
impl CrateDefMap {
pub(crate) fn crate_def_map_query(
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,
krate: CrateId,
) -> Arc<CrateDefMap> {
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);

View File

@ -309,7 +309,7 @@ macro_rules! sweep_each_query {
hir::db::EnumDataQuery
hir::db::TraitDataQuery
hir::db::RawItemsQuery
hir::db::CrateDefMapQuery
hir::db::ComputeCrateDefMapQuery
hir::db::GenericParamsQuery
hir::db::FunctionDataQuery
hir::db::TypeAliasDataQuery