Description
I'm currently helping Fluid Protocol debug bad LSP performance on their workspace. The workspace had 20+ sway projects and 1 large "libraries" project that contain 20+ sway libraries.
When clicking through the various projects, I've noticed that the amount of RAM used can easily reach 20+ gig. It seems we are recompiling std / core and shared libraries for each project. So if we click through all 20 projects, we have compiled the std lib 20 times and store it in the servers memory. For example, if we put a print in the following query engine code
pub fn insert_programs_cache_entry(&self, entry: ProgramsCacheEntry) {
eprintln!("👷 Instering programs cache entry: {:?}", entry.path);
let mut cache = self.programs_cache.write().unwrap();
cache.insert(entry.path.clone(), entry);
}
We get the below.
Instead, we should be having a single QueryEngine stored in ServerState
that is used across each project. This way we will be able to drastically reduce the memory footprint for projects like this, and greatly speed up the time it takes for the server to initialise when a new project is navigated to.