-
Notifications
You must be signed in to change notification settings - Fork 1.7k
High memory usage #13954
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
Comments
I got a Similar issue using Rust-Analyzer Server with VsCode. OS: Archlinux On both
This is the "normal" amount of RAM (15G) while working on 1 workspace containing 8 crates I made for work. However, my total amount of Memory used at time T is 47G (28G RAM + 19G Swap). So there seems to be more than just the 15G advertised by Gnome process monitor. And sometimes, if I do a big change in the code, when saving the file with the "format on save" option enabled in VsCode, the Memory usage will increase without stopping until the computer freeze due to both the RAM and Swap being full. |
@vpochapuis are you using a Code workspace? Normally we only have two processes, so of you have more, you have multiple instances of Code running, a Code workspace, or they're hung and got started before, but didn't close. |
yes I am using a code Workspace where i have only the folders of my Rust Crates in there. (there are other things in the main folder and i don't wanna see them in my file browser while working on the project). |
I suggest using a Cargo workspace instead. It won't completely fix the memory usage, especially on certain types of codebases (ahem, blockchain), but it will help a lot as we'll no longer spawn one instance for each crate. |
I am using a Cargo workspace, which points to the different crates I am using, which are not all in the same folders. Before I liked to have one VsCode window per Crate, but I quickly saw in my process monitor that I had one Rust-Analyzer per window, so I had to find another way. |
I'm not sure I understand, but you might want to look into this if you have more than one rust-analyzer process running (the proc macro expander has a different name these days, but shouldn't use that much memory). |
My current setup:
Code:
Here is the list of Rust related process running: |
those proc-macro server instances indicate that you have 8 top level cargo workspaces loaded, not 1. So I believe your high memory usage comes from #14476 |
I have 1 Cargo workspace file, with 8 members, 2 binary crates and 6 library crates. Also, I don't understand why the process advertised Memory is different from the real memory usage. I am sorry if I didn't explain my situation well previously. |
Ah sorry I missed this part. This is the problem. Code workspaces currently cause each separate folder to be reported as its own workspace to r-a which has a similar effect. (havent investigated whether this is our fault or not, or if there is anything that can be done to prevent this), opened #14571 for that |
You can reduce the memory usage by making a Code workspace that only contains the Cargo workspace (and not the 8 crates), but that leads to an awful IDE experience.
Measuring memory usage is not as easy as it sounds: https://elinux.org/Android_Memory_Usage. I suspect that process monitor shows the RSS (the RAM usage, at a first approximation), but not the swap. |
@lnicola Thanks a lot! Its a chance to have people like you helping the community like this. Yeah I am more and more being upset with Code workflow.. Everyday I think whether I should try going back to Emacs or Helix and take the time to learn keybindings. What is the setup you would recommend ? |
@Veykril Thanks a lot to you too! So its an IDE issue... |
For the time being I recommend not using code workspaces and just opening the top level cargo workspace directly with VSCode |
I think it's mostly a rust-analyzer limitation. You won't get a better experience with Emacs or Helix, but rather a worse one instead. As Veykril says, you should try to structure the crates so that you can open a single directory in Code. |
@Veykril So using Code and Rust, I can't:
And I must:
I wish there was more convenient ways. |
I'm pretty sure that's going to be a bad idea in any language.
I don't know how other language servers handle this, but I wouldn't be surprised if some of them had a similar issue. |
@lnicola On emacs you can open a window( |
@vpochapuis if you still have this setup, can you check if it's working better in the latest version? |
@lnicola Hey ! When we discussed last time I changed to the "Open the root project" solution and removed my setup. However tomorrow at work I could update and set it up again to let you know if there is still the issue! |
@lnicola It seems to be fixed! Amazing! I only have one instance of rust-analyzer and rust-analyzer-proc-macro-srv per VsCode window. So opening a VsCode Workspace with several folder from the same Rust Workspace doesnt affect RAM usage like before! |
Closing as the original issue is not really workable |
rust-analyzer version: 0.4.1366-standalone
rustc version: rustc 1.66.0 (69f9c33d7 2022-12-12)
relevant settings: all defaults
While working in my workspace rust-analyzer takes normally 1-4GB of RAM, but suddenly it started continuously reading files (my drive LED lit up), had high CPU usage and 8+ GB of RAM usage.
I couldn't get a log as I just killed the process to prevent my computer from freezing (my swap space was already half full and rust-analyzer continued to reserve memory) and I haven't encountered this again, but maybe someone also gets this and the cause gets found.
The text was updated successfully, but these errors were encountered: