diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index 358ca1453d2..b65cf7341f3 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -53,7 +53,7 @@ pub struct FileRange { pub range: TextRange, } -pub const DEFAULT_LRU_CAP: usize = 128; +pub const DEFAULT_PARSE_LRU_CAP: usize = 128; pub trait FileLoader { /// Text of the file. diff --git a/crates/hir-expand/src/ast_id_map.rs b/crates/hir-expand/src/ast_id_map.rs index 2b27db0e950..e48caca790c 100644 --- a/crates/hir-expand/src/ast_id_map.rs +++ b/crates/hir-expand/src/ast_id_map.rs @@ -115,6 +115,7 @@ pub(crate) fn from_source(node: &SyntaxNode) -> AstIdMap { } } } + res.arena.shrink_to_fit(); res } diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index b9f9cbd7fba..b0c5820fb09 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -149,29 +149,33 @@ pub fn enable_proc_attr_macros(&mut self) { } pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option) { - let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP); + let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP); base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); - hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(lru_capacity); - hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); + // macro expansions are usually rather small, so we can afford to keep more of them alive + hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity); + hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity); } pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap, usize>) { use hir::db as hir_db; base_db::ParseQuery.in_db_mut(self).set_lru_capacity( - lru_capacities.get(stringify!(ParseQuery)).copied().unwrap_or(base_db::DEFAULT_LRU_CAP), + lru_capacities + .get(stringify!(ParseQuery)) + .copied() + .unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP), ); hir_db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity( lru_capacities .get(stringify!(ParseMacroExpansionQuery)) .copied() - .unwrap_or(base_db::DEFAULT_LRU_CAP), + .unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP), ); hir_db::MacroExpandQuery.in_db_mut(self).set_lru_capacity( lru_capacities .get(stringify!(MacroExpandQuery)) .copied() - .unwrap_or(base_db::DEFAULT_LRU_CAP), + .unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP), ); macro_rules! update_lru_capacity_per_query {