Skip to content

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

Closed
tareksander opened this issue Jan 14, 2023 · 23 comments
Closed

High memory usage #13954

tareksander opened this issue Jan 14, 2023 · 23 comments
Labels
A-perf performance issues C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@tareksander
Copy link

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.

@jonas-schievink jonas-schievink added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Jan 27, 2023
@Veykril Veykril added A-perf performance issues C-support Category: support questions labels Feb 3, 2023
@vpochapuis
Copy link

I got a Similar issue using Rust-Analyzer Server with VsCode.

OS: Archlinux
IDE: VsCode

On both

  • rust-analyzer version: 0.3.1472-standalone
  • rust-analyzer version: 0.4.1476-standalone

image

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).
When running pkill rust-analyzer it drops of 30G at time T+1 before slowly getting back to the previous state (VsCode restarting the server) :

image

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.

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

@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.

@vpochapuis
Copy link

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).
This happens even after a computer reboot. And I only have one window of Code open.

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

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.

@vpochapuis
Copy link

vpochapuis commented Apr 14, 2023

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.

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

I am using a code Workspace where i have only the folders of my Rust Crates in there

I am using a Cargo workspace, which points to the different crates I am using,

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).

@vpochapuis
Copy link

My current setup:
Rust:

  • Cargo Workspace (setup in a file at the root of our project)

Code:

  • 1 window with 1 workspace inside, with each Crate as a Folder opened inside (before I had 1 window for each folder, which was creating lots of instance of Rust-Analyzer, but I stopped doing so, even though I liked the convenience).

Here is the list of Rust related process running:

image

@Veykril
Copy link
Member

Veykril commented Apr 14, 2023

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

@vpochapuis
Copy link

I have 1 Cargo workspace file, with 8 members, 2 binary crates and 6 library crates.
I am not sure I understand well the fact that there is several Cargo Workspaces.
Each of those members are opened as a folder in the Code Workspace.

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.

@Veykril
Copy link
Member

Veykril commented Apr 14, 2023

Each of those members are opened as a folder in the Code Workspace.

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

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

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.

Also, I don't understand why the process advertised Memory is different from the real memory usage.

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.

@vpochapuis
Copy link

@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.
Although, would this setup be less prone to this kind of issues? Is it related to how Code handles Worskpaces, Folders and Projects? Or is it directly related to Rust-Analyzer?

What is the setup you would recommend ?

@vpochapuis
Copy link

@Veykril Thanks a lot to you too!

So its an IDE issue...

@Veykril
Copy link
Member

Veykril commented Apr 14, 2023

For the time being I recommend not using code workspaces and just opening the top level cargo workspace directly with VSCode

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

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.

@vpochapuis
Copy link

@Veykril So using Code and Rust, I can't:

  • Open 1 window per crate
  • Have 1 Folder per crate in the File browser (Code Workspace)

And I must:

  • Open the root project

I wish there was more convenient ways.
But I will do that

@lnicola
Copy link
Member

lnicola commented Apr 14, 2023

Open 1 window per crate

I'm pretty sure that's going to be a bad idea in any language.

Have 1 Folder per crate in the File browser (Code Workspace)

I don't know how other language servers handle this, but I wouldn't be surprised if some of them had a similar issue.

@vpochapuis
Copy link

@lnicola On emacs you can open a window(frame if i remember well) to reflect a buffer from the same session on another screen.
That's what I wanted to emulate a bit, because I liked using different screens while working on big projects,

@lnicola
Copy link
Member

lnicola commented May 1, 2023

@vpochapuis if you still have this setup, can you check if it's working better in the latest version?

@vpochapuis
Copy link

@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!

@vpochapuis
Copy link

@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!
Thanks!

@Veykril
Copy link
Member

Veykril commented May 2, 2023

Closing as the original issue is not really workable

@Veykril Veykril closed this as completed May 2, 2023
@praem90
Copy link

praem90 commented Feb 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-perf performance issues C-support Category: support questions S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

6 participants