My main machine uses Ubuntu 22 and has 8gb RAM and 1gb of vram. It's a fairly old machine, but it still works fine for me. However, when I'm developing with Rust and using rust-analyzer, it's very common for my machine to consistently and completely crash. Looking at memory usage, rust-analyzer would often use 1.8gb of memory.
This github issue and this reddit thread address the reason why rust-analyzer uses so much memory. Unfortunately, there doesn't seem to be a way to reduce memory usage in rust-analyzer - that's just the cost of having a nice tool like rust-analyzer. I will say however, that reducing the rust-analyzer.lru.capacity setting in vscode did slightly reduce my memory usage. I set mine to 44 (down from 128), and it did prevent crashes in some projects (not all).
So if you're going to use Rust on a low-end machine, here's a couple alternative options.
First, you can just develop and debug using
cargo watch. Edit your code, save the files, and look for errors and warnings. Not ideal, but it is an option and you get used to it.
Second, you could do the first option and also get ctags to work so you have autocomplete and suggestions in your IDE. I haven't explored this option, but ctags are very lightweight and fast from what I hear.
Third, for some projects, rust-analyzer on its own was not enough to crash my computer. But running rust-analyzer AND doing a
cargo build or
cargo run WAS enough to push me over the limit. In that situation, I would either kill other memory heavy applications on my system, or I would protect myself from a crash by limiting the memory and cpu on the cargo command using
systemd-run --scope -p CPUQuota=20% -p MemoryMax=1048M -p MemoryHigh=1048M --user cargo run
It's not ideal, but it did save me from some crashes by killing the cargo process before it crashed my computer.
Other than that, I'm not sure there are any other options. In the end, my longer term solution is to upgrade my other computer to 16gb RAM and use that for rust development. RAM isn't very expensive so it's worth doing if you have slots available.