Optimize and profile

This commit is contained in:
Aleksey Kladov 2019-12-21 18:45:46 +01:00
parent 6d8a2ec3dd
commit d4b135f38c
6 changed files with 19 additions and 3 deletions

1
Cargo.lock generated
View File

@ -948,6 +948,7 @@ dependencies = [
"ra_hir_def 0.1.0", "ra_hir_def 0.1.0",
"ra_hir_expand 0.1.0", "ra_hir_expand 0.1.0",
"ra_hir_ty 0.1.0", "ra_hir_ty 0.1.0",
"ra_prof 0.1.0",
"ra_syntax 0.1.0", "ra_syntax 0.1.0",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@ -14,6 +14,7 @@ either = "1.5"
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_prof = { path = "../ra_prof" }
hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }

View File

@ -7,6 +7,7 @@
StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId, StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId,
}; };
use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
use ra_prof::profile;
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode, NameOwner}, ast::{self, AstNode, NameOwner},
match_ast, SyntaxNode, match_ast, SyntaxNode,
@ -169,6 +170,7 @@ pub fn from_source(db: &impl HirDatabase, src: InFile<ast::TypeParam>) -> Option
impl Module { impl Module {
pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> { pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
let _p = profile("Module::from_declaration");
let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
let parent_module = match parent_declaration { let parent_module = match parent_declaration {
@ -191,6 +193,7 @@ pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Opti
} }
pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> { pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> {
let _p = profile("Module::from_definition");
match src.value { match src.value {
ModuleSource::Module(ref module) => { ModuleSource::Module(ref module) => {
assert!(!module.has_semi()); assert!(!module.has_semi());
@ -214,6 +217,7 @@ pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Opti
} }
fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap {
let _p = profile("analyze_container");
return child_by_source(db, src).unwrap_or_default(); return child_by_source(db, src).unwrap_or_default();
fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> { fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> {

View File

@ -26,6 +26,7 @@
method_resolution::{self, implements_trait}, method_resolution::{self, implements_trait},
Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty,
}; };
use ra_prof::profile;
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
match_ast, AstPtr, match_ast, AstPtr,
@ -83,6 +84,7 @@ fn def_with_body_from_child_node(
db: &impl HirDatabase, db: &impl HirDatabase,
child: InFile<&SyntaxNode>, child: InFile<&SyntaxNode>,
) -> Option<DefWithBody> { ) -> Option<DefWithBody> {
let _p = profile("def_with_body_from_child_node");
child.cloned().ancestors_with_macros(db).find_map(|node| { child.cloned().ancestors_with_macros(db).find_map(|node| {
let n = &node.value; let n = &node.value;
match_ast! { match_ast! {
@ -169,6 +171,7 @@ pub fn new(
node: InFile<&SyntaxNode>, node: InFile<&SyntaxNode>,
offset: Option<TextUnit>, offset: Option<TextUnit>,
) -> SourceAnalyzer { ) -> SourceAnalyzer {
let _p = profile("SourceAnalyzer::new");
let def_with_body = def_with_body_from_child_node(db, node); let def_with_body = def_with_body_from_child_node(db, node);
if let Some(def) = def_with_body { if let Some(def) = def_with_body {
let (_body, source_map) = db.body_with_source_map(def.into()); let (_body, source_map) = db.body_with_source_map(def.into());

View File

@ -11,6 +11,7 @@
ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId, ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId,
}; };
use ra_arena::{map::ArenaMap, Arena}; use ra_arena::{map::ArenaMap, Arena};
use ra_prof::profile;
use ra_syntax::{ast, AstNode, AstPtr}; use ra_syntax::{ast, AstNode, AstPtr};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -168,6 +169,7 @@ pub(crate) fn body_with_source_map_query(
db: &impl DefDatabase, db: &impl DefDatabase,
def: DefWithBodyId, def: DefWithBodyId,
) -> (Arc<Body>, Arc<BodySourceMap>) { ) -> (Arc<Body>, Arc<BodySourceMap>) {
let _p = profile("body_with_source_map_query");
let mut params = None; let mut params = None;
let (file_id, module, body) = match def { let (file_id, module, body) = match def {

View File

@ -1,12 +1,15 @@
//! FIXME: write short doc here //! FIXME: write short doc here
use crate::{db::RootDatabase, FileId};
use hir::{HirDisplay, SourceAnalyzer}; use hir::{HirDisplay, SourceAnalyzer};
use once_cell::unsync::Lazy;
use ra_prof::profile;
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode, TypeAscriptionOwner}, ast::{self, AstNode, TypeAscriptionOwner},
match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange,
}; };
use crate::{db::RootDatabase, FileId};
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum InlayKind { pub enum InlayKind {
TypeHint, TypeHint,
@ -27,7 +30,7 @@ pub(crate) fn inlay_hints(
) -> Vec<InlayHint> { ) -> Vec<InlayHint> {
file.syntax() file.syntax()
.descendants() .descendants()
.map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default()) .flat_map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length))
.flatten() .flatten()
.collect() .collect()
} }
@ -38,7 +41,9 @@ fn get_inlay_hints(
node: &SyntaxNode, node: &SyntaxNode,
max_inlay_hint_length: Option<usize>, max_inlay_hint_length: Option<usize>,
) -> Option<Vec<InlayHint>> { ) -> Option<Vec<InlayHint>> {
let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); let _p = profile("get_inlay_hints");
let analyzer =
Lazy::new(|| SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None));
match_ast! { match_ast! {
match node { match node {
ast::LetStmt(it) => { ast::LetStmt(it) => {