Skip to content

Allow a single Engines to be used across a workspace #5856

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

Closed
JoshuaBatty opened this issue Apr 15, 2024 · 2 comments · Fixed by #7139
Closed

Allow a single Engines to be used across a workspace #5856

JoshuaBatty opened this issue Apr 15, 2024 · 2 comments · Fixed by #7139
Assignees
Labels
big this task is hard and will take a while compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen language server LSP server team:compiler Compiler Team

Comments

@JoshuaBatty
Copy link
Member

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.

Screenshot 2024-04-15 at 1 30 43 pm

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.

@JoshuaBatty JoshuaBatty self-assigned this Apr 15, 2024
@JoshuaBatty JoshuaBatty added the language server LSP server label Apr 15, 2024
@JoshuaBatty
Copy link
Member Author

related to #5645

@JoshuaBatty
Copy link
Member Author

JoshuaBatty commented Apr 16, 2024

Ok it's not as simple as just having the QueryEngine shared across workspace members. This will allow us to share the cached AST but the type and decl engines still need to be populated. What we probably want is to have the Engines and other items like the TokenMap stored in the ServerState rather than within each Session.

This is going to involve quite a bit of code re-arranging but should be feasible.

@JoshuaBatty JoshuaBatty changed the title Use a single QueryEngine in the language server to share cache across large workspaces Use a single Engines & TokenMap in the language server to share cache across large workspaces Apr 16, 2024
JoshuaBatty added a commit that referenced this issue Apr 16, 2024
## Description
1st part of a code reorganization. Documents are now stored in
ServerState meaning the documents can be shared across workspace
members.

No new code was added.

related to #5856 

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
@JoshuaBatty JoshuaBatty added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Jul 5, 2024
@JoshuaBatty JoshuaBatty removed their assignment Jul 5, 2024
@JoshuaBatty JoshuaBatty added the big this task is hard and will take a while label Jul 5, 2024
@JoshuaBatty JoshuaBatty changed the title Use a single Engines & TokenMap in the language server to share cache across large workspaces Allow a single Engines to be used across a workspace Jul 5, 2024
@IGI-111 IGI-111 added the team:compiler Compiler Team label Feb 10, 2025
@JoshuaBatty JoshuaBatty self-assigned this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big this task is hard and will take a while compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen language server LSP server team:compiler Compiler Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants