Skip to content

Commit 5750d81

Browse files
committed
Auto merge of #14632 - Veykril:lru-macro, r=lnicola
internal: Increase LRU cache size for parse_expansion and macro_expand queries
2 parents 442a769 + 6253fc0 commit 5750d81

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

crates/base-db/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct FileRange {
5353
pub range: TextRange,
5454
}
5555

56-
pub const DEFAULT_LRU_CAP: usize = 128;
56+
pub const DEFAULT_PARSE_LRU_CAP: usize = 128;
5757

5858
pub trait FileLoader {
5959
/// Text of the file.

crates/hir-expand/src/ast_id_map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl AstIdMap {
115115
}
116116
}
117117
}
118+
res.arena.shrink_to_fit();
118119
res
119120
}
120121

crates/ide-db/src/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,33 @@ impl RootDatabase {
149149
}
150150

151151
pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option<usize>) {
152-
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
152+
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP);
153153
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
154-
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
155-
hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
154+
// macro expansions are usually rather small, so we can afford to keep more of them alive
155+
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
156+
hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
156157
}
157158

158159
pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usize>) {
159160
use hir::db as hir_db;
160161

161162
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(
162-
lru_capacities.get(stringify!(ParseQuery)).copied().unwrap_or(base_db::DEFAULT_LRU_CAP),
163+
lru_capacities
164+
.get(stringify!(ParseQuery))
165+
.copied()
166+
.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP),
163167
);
164168
hir_db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(
165169
lru_capacities
166170
.get(stringify!(ParseMacroExpansionQuery))
167171
.copied()
168-
.unwrap_or(base_db::DEFAULT_LRU_CAP),
172+
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
169173
);
170174
hir_db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(
171175
lru_capacities
172176
.get(stringify!(MacroExpandQuery))
173177
.copied()
174-
.unwrap_or(base_db::DEFAULT_LRU_CAP),
178+
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
175179
);
176180

177181
macro_rules! update_lru_capacity_per_query {

0 commit comments

Comments
 (0)