Memoize block_item_tree_query

This commit is contained in:
Lukas Wirth 2023-08-10 19:22:46 +02:00
parent fde2d9b47c
commit bfad781a77
2 changed files with 4 additions and 5 deletions

View File

@ -83,9 +83,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
#[salsa::invoke(ItemTree::block_item_tree_query)]
// FIXME: Investigate memory usage increase if this were not transparent
// Also make sure to `shrink_to_fit` if you do
#[salsa::transparent]
fn block_item_tree_query(&self, block_id: BlockId) -> Arc<ItemTree>;
#[salsa::invoke(crate_def_map_wait)]

View File

@ -148,7 +148,9 @@ impl ItemTree {
let block = loc.ast_id.to_node(db.upcast());
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
Arc::new(ctx.lower_block(&block))
let mut item_tree = ctx.lower_block(&block);
item_tree.shrink_to_fit();
Arc::new(item_tree)
}
/// Returns an iterator over all items located at the top level of the `HirFileId` this
@ -383,7 +385,7 @@ impl TreeId {
pub(crate) fn item_tree(&self, db: &dyn DefDatabase) -> Arc<ItemTree> {
match self.block {
Some(block) => ItemTree::block_item_tree_query(db, block),
Some(block) => db.block_item_tree_query(block),
None => db.file_item_tree(self.file),
}
}