Skip to content

Commit 0f68fed

Browse files
bors[bot]Jonas Schievink
andauthored
Merge #5209
5209: Fixes to memory usage stats r=matklad a=jonas-schievink This brings the unaccounted memory down from 287mb to 250mb, and displays memory used by VFS and "other" allocations. Co-authored-by: Jonas Schievink <[email protected]>
2 parents dceec61 + f01e7e3 commit 0f68fed

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

crates/ra_ide_db/src/change.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,10 @@ impl RootDatabase {
191191

192192
// AstDatabase
193193
hir::db::AstIdMapQuery
194-
hir::db::InternMacroQuery
195194
hir::db::MacroArgQuery
196195
hir::db::MacroDefQuery
197196
hir::db::ParseMacroQuery
198197
hir::db::MacroExpandQuery
199-
hir::db::InternEagerExpansionQuery
200198

201199
// DefDatabase
202200
hir::db::ItemTreeQuery
@@ -221,17 +219,6 @@ impl RootDatabase {
221219
hir::db::DocumentationQuery
222220
hir::db::ImportMapQuery
223221

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-
235222
// HirDatabase
236223
hir::db::InferQueryQuery
237224
hir::db::TyQuery
@@ -246,10 +233,6 @@ impl RootDatabase {
246233
hir::db::InherentImplsInCrateQuery
247234
hir::db::TraitImplsInCrateQuery
248235
hir::db::TraitImplsInDepsQuery
249-
hir::db::InternTypeCtorQuery
250-
hir::db::InternTypeParamIdQuery
251-
hir::db::InternChalkImplQuery
252-
hir::db::InternAssocTyValueQuery
253236
hir::db::AssociatedTyDataQuery
254237
hir::db::TraitDatumQuery
255238
hir::db::StructDatumQuery
@@ -264,6 +247,36 @@ impl RootDatabase {
264247
// LineIndexDatabase
265248
crate::LineIndexQuery
266249
];
250+
251+
// To collect interned data, we need to bump the revision counter by performing a synthetic
252+
// write.
253+
// We do this after collecting the non-interned queries to correctly attribute memory used
254+
// by interned data.
255+
self.runtime.synthetic_write(Durability::HIGH);
256+
257+
sweep_each_query![
258+
// AstDatabase
259+
hir::db::InternMacroQuery
260+
hir::db::InternEagerExpansionQuery
261+
262+
// InternDatabase
263+
hir::db::InternFunctionQuery
264+
hir::db::InternStructQuery
265+
hir::db::InternUnionQuery
266+
hir::db::InternEnumQuery
267+
hir::db::InternConstQuery
268+
hir::db::InternStaticQuery
269+
hir::db::InternTraitQuery
270+
hir::db::InternTypeAliasQuery
271+
hir::db::InternImplQuery
272+
273+
// HirDatabase
274+
hir::db::InternTypeCtorQuery
275+
hir::db::InternTypeParamIdQuery
276+
hir::db::InternChalkImplQuery
277+
hir::db::InternAssocTyValueQuery
278+
];
279+
267280
acc.sort_by_key(|it| std::cmp::Reverse(it.1));
268281
acc
269282
}

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,22 @@ pub fn analysis_stats(
273273
println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
274274

275275
if memory_usage {
276-
for (name, bytes) in host.per_query_memory_usage() {
277-
println!("{:>8} {}", bytes, name)
278-
}
276+
let mut mem = host.per_query_memory_usage();
277+
278+
let before = ra_prof::memory_usage();
279+
drop(vfs);
280+
let vfs = before.allocated - ra_prof::memory_usage().allocated;
281+
mem.push(("VFS".into(), vfs));
282+
279283
let before = ra_prof::memory_usage();
280284
drop(host);
281-
println!("leftover: {}", before.allocated - ra_prof::memory_usage().allocated)
285+
mem.push(("Unaccounted".into(), before.allocated - ra_prof::memory_usage().allocated));
286+
287+
mem.push(("Remaining".into(), ra_prof::memory_usage().allocated));
288+
289+
for (name, bytes) in mem {
290+
println!("{:>8} {}", bytes, name)
291+
}
282292
}
283293

284294
Ok(())

0 commit comments

Comments
 (0)