aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src/change.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db/src/change.rs')
-rw-r--r--crates/ra_ide_db/src/change.rs39
1 files changed, 22 insertions, 17 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index 2504d7a33..a1bb3043b 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -5,8 +5,7 @@ use std::{fmt, sync::Arc, time};
5 5
6use ra_db::{ 6use ra_db::{
7 salsa::{Database, Durability, SweepStrategy}, 7 salsa::{Database, Durability, SweepStrategy},
8 CrateGraph, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot, 8 CrateGraph, FileId, SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId,
9 SourceRootId,
10}; 9};
11use ra_prof::{memory_usage, profile, Bytes}; 10use ra_prof::{memory_usage, profile, Bytes};
12use rustc_hash::FxHashSet; 11use rustc_hash::FxHashSet;
@@ -57,14 +56,14 @@ impl AnalysisChange {
57#[derive(Debug)] 56#[derive(Debug)]
58struct AddFile { 57struct AddFile {
59 file_id: FileId, 58 file_id: FileId,
60 path: RelativePathBuf, 59 path: String,
61 text: Arc<String>, 60 text: Arc<String>,
62} 61}
63 62
64#[derive(Debug)] 63#[derive(Debug)]
65struct RemoveFile { 64struct RemoveFile {
66 file_id: FileId, 65 file_id: FileId,
67 path: RelativePathBuf, 66 path: String,
68} 67}
69 68
70#[derive(Default)] 69#[derive(Default)]
@@ -147,37 +146,46 @@ impl RootDatabase {
147 146
148 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 147 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
149 148
150 self.query(ra_db::ParseQuery).sweep(sweep); 149 ra_db::ParseQuery.in_db(self).sweep(sweep);
151 self.query(hir::db::ParseMacroQuery).sweep(sweep); 150 hir::db::ParseMacroQuery.in_db(self).sweep(sweep);
152 151
153 // Macros do take significant space, but less then the syntax trees 152 // Macros do take significant space, but less then the syntax trees
154 // self.query(hir::db::MacroDefQuery).sweep(sweep); 153 // self.query(hir::db::MacroDefQuery).sweep(sweep);
155 // self.query(hir::db::MacroArgQuery).sweep(sweep); 154 // self.query(hir::db::MacroArgQuery).sweep(sweep);
156 // self.query(hir::db::MacroExpandQuery).sweep(sweep); 155 // self.query(hir::db::MacroExpandQuery).sweep(sweep);
157 156
158 self.query(hir::db::AstIdMapQuery).sweep(sweep); 157 hir::db::AstIdMapQuery.in_db(self).sweep(sweep);
159 158
160 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); 159 hir::db::BodyWithSourceMapQuery.in_db(self).sweep(sweep);
161 160
162 self.query(hir::db::ExprScopesQuery).sweep(sweep); 161 hir::db::ExprScopesQuery.in_db(self).sweep(sweep);
163 self.query(hir::db::InferQueryQuery).sweep(sweep); 162 hir::db::InferQueryQuery.in_db(self).sweep(sweep);
164 self.query(hir::db::BodyQuery).sweep(sweep); 163 hir::db::BodyQuery.in_db(self).sweep(sweep);
165 } 164 }
166 165
166 // Feature: Memory Usage
167 //
168 // Clears rust-analyzer's internal database and prints memory usage statistics.
169 //
170 // |===
171 // | Editor | Action Name
172 //
173 // | VS Code | **Rust Analyzer: Memory Usage (Clears Database)**
174 // |===
167 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { 175 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
168 let mut acc: Vec<(String, Bytes)> = vec![]; 176 let mut acc: Vec<(String, Bytes)> = vec![];
169 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 177 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
170 macro_rules! sweep_each_query { 178 macro_rules! sweep_each_query {
171 ($($q:path)*) => {$( 179 ($($q:path)*) => {$(
172 let before = memory_usage().allocated; 180 let before = memory_usage().allocated;
173 self.query($q).sweep(sweep); 181 $q.in_db(self).sweep(sweep);
174 let after = memory_usage().allocated; 182 let after = memory_usage().allocated;
175 let q: $q = Default::default(); 183 let q: $q = Default::default();
176 let name = format!("{:?}", q); 184 let name = format!("{:?}", q);
177 acc.push((name, before - after)); 185 acc.push((name, before - after));
178 186
179 let before = memory_usage().allocated; 187 let before = memory_usage().allocated;
180 self.query($q).sweep(sweep.discard_everything()); 188 $q.in_db(self).sweep(sweep.discard_everything());
181 let after = memory_usage().allocated; 189 let after = memory_usage().allocated;
182 let q: $q = Default::default(); 190 let q: $q = Default::default();
183 let name = format!("{:?} (deps)", q); 191 let name = format!("{:?} (deps)", q);
@@ -252,7 +260,7 @@ impl RootDatabase {
252 // write. 260 // write.
253 // We do this after collecting the non-interned queries to correctly attribute memory used 261 // We do this after collecting the non-interned queries to correctly attribute memory used
254 // by interned data. 262 // by interned data.
255 self.runtime.synthetic_write(Durability::HIGH); 263 self.salsa_runtime_mut().synthetic_write(Durability::HIGH);
256 264
257 sweep_each_query![ 265 sweep_each_query![
258 // AstDatabase 266 // AstDatabase
@@ -271,10 +279,7 @@ impl RootDatabase {
271 hir::db::InternImplQuery 279 hir::db::InternImplQuery
272 280
273 // HirDatabase 281 // HirDatabase
274 hir::db::InternTypeCtorQuery
275 hir::db::InternTypeParamIdQuery 282 hir::db::InternTypeParamIdQuery
276 hir::db::InternChalkImplQuery
277 hir::db::InternAssocTyValueQuery
278 ]; 283 ];
279 284
280 acc.sort_by_key(|it| std::cmp::Reverse(it.1)); 285 acc.sort_by_key(|it| std::cmp::Reverse(it.1));