diff options
author | Aleksey Kladov <[email protected]> | 2019-06-02 18:15:10 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-02 18:15:10 +0100 |
commit | 8b7f58976b32ccc768e35151b77aa9ea004b7495 (patch) | |
tree | 272f93a4431ca77d6cce8ee43c0d6d4f3c636701 /crates/ra_ide_api/src | |
parent | b40c6de8a6887e6c184fca5c9188d26ee402df23 (diff) |
don't cache parses twice
Before this commit, `Parse`s for original file ended up two times in
salsa's db: first, when we parse original file, and second, when we
parse macro or a file.
Given that parse trees are the worst ofenders in terms of memory, it
makes sense to make sure we store them only once.
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 34 |
2 files changed, 29 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 02814ce56..247dc0fee 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -226,7 +226,7 @@ impl RootDatabase { | |||
226 | 226 | ||
227 | self.query(ra_db::ParseQuery).sweep(sweep); | 227 | self.query(ra_db::ParseQuery).sweep(sweep); |
228 | 228 | ||
229 | self.query(hir::db::ParseOrExpandQuery).sweep(sweep); | 229 | self.query(hir::db::ParseMacroQuery).sweep(sweep); |
230 | self.query(hir::db::MacroDefQuery).sweep(sweep); | 230 | self.query(hir::db::MacroDefQuery).sweep(sweep); |
231 | self.query(hir::db::MacroArgQuery).sweep(sweep); | 231 | self.query(hir::db::MacroArgQuery).sweep(sweep); |
232 | self.query(hir::db::MacroExpandQuery).sweep(sweep); | 232 | self.query(hir::db::MacroExpandQuery).sweep(sweep); |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 822279812..0cdeb15eb 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -4,12 +4,12 @@ use std::{ | |||
4 | sync::Arc, | 4 | sync::Arc, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use ra_syntax::{TreeArc, SyntaxNode}; | 7 | use ra_syntax::{TreeArc, SyntaxNode, Parse, AstNode}; |
8 | use ra_db::{ | 8 | use ra_db::{ |
9 | FileTextQuery, SourceRootId, | 9 | FileTextQuery, SourceRootId, |
10 | salsa::{Database, debug::{DebugQueryTable, TableEntry}}, | 10 | salsa::{Database, debug::{DebugQueryTable, TableEntry}}, |
11 | }; | 11 | }; |
12 | use hir::HirFileId; | 12 | use hir::MacroFile; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | FileId, db::RootDatabase, | 15 | FileId, db::RootDatabase, |
@@ -17,18 +17,23 @@ use crate::{ | |||
17 | }; | 17 | }; |
18 | 18 | ||
19 | pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | 19 | pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { |
20 | db.query(hir::db::ParseOrExpandQuery).entries::<SyntaxTreeStats>() | 20 | db.query(ra_db::ParseQuery).entries::<SyntaxTreeStats>() |
21 | } | ||
22 | pub(crate) fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | ||
23 | db.query(hir::db::ParseMacroQuery).entries::<SyntaxTreeStats>() | ||
21 | } | 24 | } |
22 | 25 | ||
23 | pub(crate) fn status(db: &RootDatabase) -> String { | 26 | pub(crate) fn status(db: &RootDatabase) -> String { |
24 | let files_stats = db.query(FileTextQuery).entries::<FilesStats>(); | 27 | let files_stats = db.query(FileTextQuery).entries::<FilesStats>(); |
25 | let syntax_tree_stats = syntax_tree_stats(db); | 28 | let syntax_tree_stats = syntax_tree_stats(db); |
29 | let macro_syntax_tree_stats = macro_syntax_tree_stats(db); | ||
26 | let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>(); | 30 | let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>(); |
27 | format!( | 31 | format!( |
28 | "{}\n{}\n{}\n\n\nmemory:\n{}\ngc {:?} seconds ago", | 32 | "{}\n{}\n{}\n{} (macros)\n\n\nmemory:\n{}\ngc {:?} seconds ago", |
29 | files_stats, | 33 | files_stats, |
30 | symbols_stats, | 34 | symbols_stats, |
31 | syntax_tree_stats, | 35 | syntax_tree_stats, |
36 | macro_syntax_tree_stats, | ||
32 | MemoryStats::current(), | 37 | MemoryStats::current(), |
33 | db.last_gc.elapsed().as_secs(), | 38 | db.last_gc.elapsed().as_secs(), |
34 | ) | 39 | ) |
@@ -73,10 +78,27 @@ impl fmt::Display for SyntaxTreeStats { | |||
73 | } | 78 | } |
74 | } | 79 | } |
75 | 80 | ||
76 | impl FromIterator<TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats { | 81 | impl FromIterator<TableEntry<FileId, Parse>> for SyntaxTreeStats { |
82 | fn from_iter<T>(iter: T) -> SyntaxTreeStats | ||
83 | where | ||
84 | T: IntoIterator<Item = TableEntry<FileId, Parse>>, | ||
85 | { | ||
86 | let mut res = SyntaxTreeStats::default(); | ||
87 | for entry in iter { | ||
88 | res.total += 1; | ||
89 | if let Some(tree) = entry.value.as_ref().map(|it| &it.tree) { | ||
90 | res.retained += 1; | ||
91 | res.retained_size += tree.syntax().memory_size_of_subtree(); | ||
92 | } | ||
93 | } | ||
94 | res | ||
95 | } | ||
96 | } | ||
97 | |||
98 | impl FromIterator<TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats { | ||
77 | fn from_iter<T>(iter: T) -> SyntaxTreeStats | 99 | fn from_iter<T>(iter: T) -> SyntaxTreeStats |
78 | where | 100 | where |
79 | T: IntoIterator<Item = TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>>, | 101 | T: IntoIterator<Item = TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>>, |
80 | { | 102 | { |
81 | let mut res = SyntaxTreeStats::default(); | 103 | let mut res = SyntaxTreeStats::default(); |
82 | for entry in iter { | 104 | for entry in iter { |