diff options
Diffstat (limited to 'crates/ra_ide_db/src/change.rs')
-rw-r--r-- | crates/ra_ide_db/src/change.rs | 87 |
1 files changed, 53 insertions, 34 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index b507000f2..32d9a8d1f 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 | ||
6 | use ra_db::{ | 6 | use 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 | }; |
11 | use ra_prof::{memory_usage, profile, Bytes}; | 10 | use ra_prof::{memory_usage, profile, Bytes}; |
12 | use rustc_hash::FxHashSet; | 11 | use rustc_hash::FxHashSet; |
@@ -57,14 +56,14 @@ impl AnalysisChange { | |||
57 | #[derive(Debug)] | 56 | #[derive(Debug)] |
58 | struct AddFile { | 57 | struct 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)] |
65 | struct RemoveFile { | 64 | struct 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::MacroArgTextQuery).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); |
@@ -191,12 +199,10 @@ impl RootDatabase { | |||
191 | 199 | ||
192 | // AstDatabase | 200 | // AstDatabase |
193 | hir::db::AstIdMapQuery | 201 | hir::db::AstIdMapQuery |
194 | hir::db::InternMacroQuery | 202 | hir::db::MacroArgTextQuery |
195 | hir::db::MacroArgQuery | ||
196 | hir::db::MacroDefQuery | 203 | hir::db::MacroDefQuery |
197 | hir::db::ParseMacroQuery | 204 | hir::db::ParseMacroQuery |
198 | hir::db::MacroExpandQuery | 205 | hir::db::MacroExpandQuery |
199 | hir::db::InternEagerExpansionQuery | ||
200 | 206 | ||
201 | // DefDatabase | 207 | // DefDatabase |
202 | hir::db::ItemTreeQuery | 208 | hir::db::ItemTreeQuery |
@@ -221,17 +227,6 @@ impl RootDatabase { | |||
221 | hir::db::DocumentationQuery | 227 | hir::db::DocumentationQuery |
222 | hir::db::ImportMapQuery | 228 | hir::db::ImportMapQuery |
223 | 229 | ||
224 | // InternDatabase | ||
225 | hir::db::InternFunctionQuery | ||
226 | hir::db::InternStructQuery | ||
227 | hir::db::InternUnionQuery | ||
228 | hir::db::InternEnumQuery | ||
229 | hir::db::InternConstQuery | ||
230 | hir::db::InternStaticQuery | ||
231 | hir::db::InternTraitQuery | ||
232 | hir::db::InternTypeAliasQuery | ||
233 | hir::db::InternImplQuery | ||
234 | |||
235 | // HirDatabase | 230 | // HirDatabase |
236 | hir::db::InferQueryQuery | 231 | hir::db::InferQueryQuery |
237 | hir::db::TyQuery | 232 | hir::db::TyQuery |
@@ -243,12 +238,9 @@ impl RootDatabase { | |||
243 | hir::db::GenericPredicatesForParamQuery | 238 | hir::db::GenericPredicatesForParamQuery |
244 | hir::db::GenericPredicatesQuery | 239 | hir::db::GenericPredicatesQuery |
245 | hir::db::GenericDefaultsQuery | 240 | hir::db::GenericDefaultsQuery |
246 | hir::db::ImplsInCrateQuery | 241 | hir::db::InherentImplsInCrateQuery |
247 | hir::db::ImplsFromDepsQuery | 242 | hir::db::TraitImplsInCrateQuery |
248 | hir::db::InternTypeCtorQuery | 243 | hir::db::TraitImplsInDepsQuery |
249 | hir::db::InternTypeParamIdQuery | ||
250 | hir::db::InternChalkImplQuery | ||
251 | hir::db::InternAssocTyValueQuery | ||
252 | hir::db::AssociatedTyDataQuery | 244 | hir::db::AssociatedTyDataQuery |
253 | hir::db::TraitDatumQuery | 245 | hir::db::TraitDatumQuery |
254 | hir::db::StructDatumQuery | 246 | hir::db::StructDatumQuery |
@@ -263,6 +255,33 @@ impl RootDatabase { | |||
263 | // LineIndexDatabase | 255 | // LineIndexDatabase |
264 | crate::LineIndexQuery | 256 | crate::LineIndexQuery |
265 | ]; | 257 | ]; |
258 | |||
259 | // To collect interned data, we need to bump the revision counter by performing a synthetic | ||
260 | // write. | ||
261 | // We do this after collecting the non-interned queries to correctly attribute memory used | ||
262 | // by interned data. | ||
263 | self.salsa_runtime_mut().synthetic_write(Durability::HIGH); | ||
264 | |||
265 | sweep_each_query![ | ||
266 | // AstDatabase | ||
267 | hir::db::InternMacroQuery | ||
268 | hir::db::InternEagerExpansionQuery | ||
269 | |||
270 | // InternDatabase | ||
271 | hir::db::InternFunctionQuery | ||
272 | hir::db::InternStructQuery | ||
273 | hir::db::InternUnionQuery | ||
274 | hir::db::InternEnumQuery | ||
275 | hir::db::InternConstQuery | ||
276 | hir::db::InternStaticQuery | ||
277 | hir::db::InternTraitQuery | ||
278 | hir::db::InternTypeAliasQuery | ||
279 | hir::db::InternImplQuery | ||
280 | |||
281 | // HirDatabase | ||
282 | hir::db::InternTypeParamIdQuery | ||
283 | ]; | ||
284 | |||
266 | acc.sort_by_key(|it| std::cmp::Reverse(it.1)); | 285 | acc.sort_by_key(|it| std::cmp::Reverse(it.1)); |
267 | acc | 286 | acc |
268 | } | 287 | } |