Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP Optimization: Wrap programs_cache in an Arc #5472

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions sway-core/src/query_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ pub type ProgramsCacheMap = HashMap<ModulePath, ProgramsCacheEntry>;

#[derive(Debug, Default)]
pub struct QueryEngine {
parse_module_cache: RwLock<ModuleCacheMap>,
programs_cache: RwLock<ProgramsCacheMap>,
parse_module_cache: Arc<RwLock<ModuleCacheMap>>,
programs_cache: Arc<RwLock<ProgramsCacheMap>>,
}

impl Clone for QueryEngine {
fn clone(&self) -> Self {
Self {
parse_module_cache: RwLock::new(self.parse_module_cache.read().unwrap().clone()),
programs_cache: RwLock::new(self.programs_cache.read().unwrap().clone()),
parse_module_cache: self.parse_module_cache.clone(),
programs_cache: self.programs_cache.clone(),
}
}
}
Expand All @@ -67,11 +67,10 @@ impl QueryEngine {
}

pub fn insert_parse_module_cache_entry(&self, entry: ModuleCacheEntry) {
let mut cache = self.parse_module_cache.write().unwrap();
let path = entry.path.clone();
let include_tests = entry.include_tests;

let key = ModuleCacheKey::new(path, include_tests);
let mut cache = self.parse_module_cache.write().unwrap();
cache.insert(key, entry);
}

Expand Down
Loading