mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-11 20:58:54 +00:00
try to optimize things unsuccessfully
Baseline ``` Database loaded: 598.40ms, 304minstr, 118mb (metadata 390.57ms, 21minstr, 841kb; build 111.31ms, 8764kinstr, -214kb) crates: 39, mods: 824, decls: 18647, fns: 13910 Item Collection: 9.70s, 75ginstr, 377mb exprs: 382426, ??ty: 387 (0%), ?ty: 285 (0%), !ty: 145 Inference: 43.16s, 342ginstr, 641mb Total: 52.86s, 417ginstr, 1018mb ``` Eager ``` Database loaded: 625.86ms, 304minstr, 118mb (metadata 414.52ms, 21minstr, 841kb; build 113.81ms, 8764kinstr, -230kb) crates: 39, mods: 824, decls: 18647, fns: 13910 Item Collection: 10.09s, 75ginstr, 389mb exprs: 382426, ??ty: 387 (0%), ?ty: 285 (0%), !ty: 145 Inference: 43.27s, 341ginstr, 644mb Total: 53.37s, 417ginstr, 1034mb ``` Lazy ``` Database loaded: 626.34ms, 304minstr, 118mb (metadata 416.26ms, 21minstr, 841kb; build 113.67ms, 8750kinstr, -209kb) crates: 39, mods: 824, decls: 18647, fns: 13910 Item Collection: 10.16s, 75ginstr, 389mb exprs: 382426, ??ty: 387 (0%), ?ty: 285 (0%), !ty: 145 Inference: 44.51s, 342ginstr, 644mb Total: 54.67s, 417ginstr, 1034mb ```
This commit is contained in:
parent
c603b9043f
commit
4f3fc6fa1a
3 changed files with 24 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -529,6 +529,7 @@ dependencies = [
|
|||
"la-arena",
|
||||
"limit",
|
||||
"mbe",
|
||||
"once_cell",
|
||||
"profile",
|
||||
"rustc-hash",
|
||||
"syntax",
|
||||
|
|
|
@ -16,6 +16,7 @@ either = "1.5.3"
|
|||
rustc-hash = "1.0.0"
|
||||
la-arena = { version = "0.3.0", path = "../../lib/arena" }
|
||||
itertools = "0.10.0"
|
||||
once_cell = "1"
|
||||
|
||||
base_db = { path = "../base_db", version = "0.0.0" }
|
||||
cfg = { path = "../cfg", version = "0.0.0" }
|
||||
|
|
|
@ -61,13 +61,29 @@ impl<N: AstNode> FileAstId<N> {
|
|||
type ErasedFileAstId = Idx<SyntaxNodePtr>;
|
||||
|
||||
/// Maps items' `SyntaxNode`s to `ErasedFileAstId`s and back.
|
||||
#[derive(Debug, PartialEq, Eq, Default)]
|
||||
#[derive(Default)]
|
||||
pub struct AstIdMap {
|
||||
arena: Arena<SyntaxNodePtr>,
|
||||
map: FxHashMap<SyntaxNodePtr, ErasedFileAstId>,
|
||||
/// Reversed mapping lazily derived from [`self.arena`].
|
||||
///
|
||||
/// FIXE: Do not store `SyntaxNodePtr` twice.
|
||||
map: once_cell::sync::OnceCell<FxHashMap<SyntaxNodePtr, ErasedFileAstId>>,
|
||||
_c: Count<Self>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for AstIdMap {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("AstIdMap").field("arena", &self.arena).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for AstIdMap {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.arena == other.arena
|
||||
}
|
||||
}
|
||||
impl Eq for AstIdMap {}
|
||||
|
||||
impl AstIdMap {
|
||||
pub(crate) fn from_source(node: &SyntaxNode) -> AstIdMap {
|
||||
assert!(node.parent().is_none());
|
||||
|
@ -91,9 +107,11 @@ impl AstIdMap {
|
|||
}
|
||||
}
|
||||
});
|
||||
res.map.extend(res.arena.iter().map(|(idx, ptr)| (ptr.clone(), idx)));
|
||||
res
|
||||
}
|
||||
fn map(&self) -> &FxHashMap<SyntaxNodePtr, ErasedFileAstId> {
|
||||
self.map.get_or_init(|| self.arena.iter().map(|(idx, ptr)| (ptr.clone(), idx)).collect())
|
||||
}
|
||||
|
||||
pub fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
|
||||
let raw = self.erased_ast_id(item.syntax());
|
||||
|
@ -102,7 +120,7 @@ impl AstIdMap {
|
|||
|
||||
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
|
||||
let ptr = SyntaxNodePtr::new(item);
|
||||
*self.map.get(&ptr).unwrap_or_else(|| {
|
||||
*self.map().get(&ptr).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Can't find {:?} in AstIdMap:\n{:?}",
|
||||
item,
|
||||
|
|
Loading…
Reference in a new issue