feat: improve caches of calls and module exports type checking (#847)

* dev: optimize log on critical paths

* dev: optimize `check_module_item`

* dev: cache source queries

* dev: cache call checking

* dev: remove source cache
This commit is contained in:
Myriad-Dreamin 2024-11-18 17:20:05 +08:00 committed by GitHub
parent 256dd3b3a5
commit ccd3cea08c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 107 additions and 33 deletions

View file

@ -533,7 +533,7 @@ impl SharedContext {
/// Get the source of a file by file path.
pub fn source_by_path(&self, p: &Path) -> FileResult<Source> {
self.world.source_by_path(p)
self.source_by_id(self.file_id_by_path(p)?)
}
/// Get a syntax object at a position.
@ -1114,16 +1114,26 @@ pub struct AnalysisRevCache {
impl RevisionManagerLike for AnalysisRevCache {
fn gc(&mut self, rev: usize) {
self.manager.gc(rev);
self.default_slot
.expr_stage
.global
.lock()
.retain(|_, r| r.0 >= rev);
self.default_slot
.type_check
.global
.lock()
.retain(|_, r| r.0 >= rev);
{
let mut max_ei = FxHashMap::default();
let es = self.default_slot.expr_stage.global.lock();
for r in es.iter() {
let rev: &mut usize = max_ei.entry(r.1.fid).or_default();
*rev = (*rev).max(r.1.revision);
}
es.retain(|_, r| r.1.revision == *max_ei.get(&r.1.fid).unwrap_or(&0));
}
{
let mut max_ti = FxHashMap::default();
let ts = self.default_slot.type_check.global.lock();
for r in ts.iter() {
let rev: &mut usize = max_ti.entry(r.1.fid).or_default();
*rev = (*rev).max(r.1.revision);
}
ts.retain(|_, r| r.1.revision == *max_ti.get(&r.1.fid).unwrap_or(&0));
}
}
}