mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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.
This commit is contained in:
parent
b40c6de8a6
commit
8b7f58976b
5 changed files with 61 additions and 33 deletions
|
@ -226,7 +226,7 @@ impl RootDatabase {
|
|||
|
||||
self.query(ra_db::ParseQuery).sweep(sweep);
|
||||
|
||||
self.query(hir::db::ParseOrExpandQuery).sweep(sweep);
|
||||
self.query(hir::db::ParseMacroQuery).sweep(sweep);
|
||||
self.query(hir::db::MacroDefQuery).sweep(sweep);
|
||||
self.query(hir::db::MacroArgQuery).sweep(sweep);
|
||||
self.query(hir::db::MacroExpandQuery).sweep(sweep);
|
||||
|
|
|
@ -4,12 +4,12 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use ra_syntax::{TreeArc, SyntaxNode};
|
||||
use ra_syntax::{TreeArc, SyntaxNode, Parse, AstNode};
|
||||
use ra_db::{
|
||||
FileTextQuery, SourceRootId,
|
||||
salsa::{Database, debug::{DebugQueryTable, TableEntry}},
|
||||
};
|
||||
use hir::HirFileId;
|
||||
use hir::MacroFile;
|
||||
|
||||
use crate::{
|
||||
FileId, db::RootDatabase,
|
||||
|
@ -17,18 +17,23 @@ use crate::{
|
|||
};
|
||||
|
||||
pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
||||
db.query(hir::db::ParseOrExpandQuery).entries::<SyntaxTreeStats>()
|
||||
db.query(ra_db::ParseQuery).entries::<SyntaxTreeStats>()
|
||||
}
|
||||
pub(crate) fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
||||
db.query(hir::db::ParseMacroQuery).entries::<SyntaxTreeStats>()
|
||||
}
|
||||
|
||||
pub(crate) fn status(db: &RootDatabase) -> String {
|
||||
let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
|
||||
let syntax_tree_stats = syntax_tree_stats(db);
|
||||
let macro_syntax_tree_stats = macro_syntax_tree_stats(db);
|
||||
let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>();
|
||||
format!(
|
||||
"{}\n{}\n{}\n\n\nmemory:\n{}\ngc {:?} seconds ago",
|
||||
"{}\n{}\n{}\n{} (macros)\n\n\nmemory:\n{}\ngc {:?} seconds ago",
|
||||
files_stats,
|
||||
symbols_stats,
|
||||
syntax_tree_stats,
|
||||
macro_syntax_tree_stats,
|
||||
MemoryStats::current(),
|
||||
db.last_gc.elapsed().as_secs(),
|
||||
)
|
||||
|
@ -73,10 +78,27 @@ impl fmt::Display for SyntaxTreeStats {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromIterator<TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats {
|
||||
impl FromIterator<TableEntry<FileId, Parse>> for SyntaxTreeStats {
|
||||
fn from_iter<T>(iter: T) -> SyntaxTreeStats
|
||||
where
|
||||
T: IntoIterator<Item = TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>>,
|
||||
T: IntoIterator<Item = TableEntry<FileId, Parse>>,
|
||||
{
|
||||
let mut res = SyntaxTreeStats::default();
|
||||
for entry in iter {
|
||||
res.total += 1;
|
||||
if let Some(tree) = entry.value.as_ref().map(|it| &it.tree) {
|
||||
res.retained += 1;
|
||||
res.retained_size += tree.syntax().memory_size_of_subtree();
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats {
|
||||
fn from_iter<T>(iter: T) -> SyntaxTreeStats
|
||||
where
|
||||
T: IntoIterator<Item = TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>>,
|
||||
{
|
||||
let mut res = SyntaxTreeStats::default();
|
||||
for entry in iter {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue