Increase LRU cache size for parse_expansion and macro_expand queries

This commit is contained in:
Lukas Wirth 2023-04-22 10:35:40 +02:00
parent f2295cda42
commit 6253fc031b
3 changed files with 12 additions and 7 deletions

View file

@ -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.

View file

@ -115,6 +115,7 @@ impl AstIdMap {
}
}
}
res.arena.shrink_to_fit();
res
}

View file

@ -149,29 +149,33 @@ impl RootDatabase {
}
pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option<usize>) {
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<Box<str>, 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 {