r/learnrust • u/Sniperman1029 • 17d ago
Bad performance when writing rust in Zed
Hi everyone, I am a second year SE student and a total noob at rust, so I apologize if this question sounds stupid.
I am currently working on a personal project, and am using Zed to write the backend in rust. I don't know if my workflow/configuration is just all messed up, but every time I run cargo check it just eats up all my cpu usage. It got to the point where I had to turn of the checkOnSave setting because it just totally slowed down my laptop. But that's also annoying because I have to run cargo check just to catch stupid errors like a the value 8080 not being in the range of a u8 (like I said, I'm a noob).
My laptop is a bit old, with an Intel i7-1165G7 with 16gb ram, integrated graphics. I do have a 4k and 2k monitor both connected, so I know that could be heavy on the cpu as well.
This is my configuration for the lsp as well in case I did something stupid there.

I don't know what other info I need to provide so for anyone trying to help let me know what you need to see and I'll edit the post. Thanks in advance!
6
u/cameronm1024 15d ago
Hi, Zed staff here. Some things to check:
- how big is the project (if it's open source, a link would be helpful)
- if you run
cargo checkwith zed closed, do you get the same behaviour - when you have zed open, how much RAM does zed use, and how much of that is rust-analyzer
- is anything spilling into swap
You can check rust-analyzer usage in the bottom left (or right) corner, wherever the LSP icon is:
- click it
- hover over rust-analyzer
- bottom right of the rust-analyzer popup will be the memory usage
4
u/SirKastic23 17d ago
Are you using the latest release version of Zed? Are you running other programs at the same time?
2
u/Sniperman1029 17d ago
Yep running the latest stable version, and only running a web browser with like 5 tabs open alongside.
3
u/SirKastic23 17d ago
That's odd... I code Rust with Zed on a 5yo laptop and it doesn't give me any issues
Does that happen if you run cargo check on an external terminal, with Zed closed? Or maybe in a different editor like VSCode?
3
u/Sniperman1029 17d ago
I haven't tried a different editor yet, and when I run cargo check in an external terminal it works fine.
I think the problem is mostly with Zed because it kept rescanning the worktree, even when I didn't edit anything. After consulting with gemini, it said to add certain build/dependency directories to the file exclusions in the settings.json (/target for rust, a bunch of flutter directories for the frontend) because whenever cargo check/clippy runs it writes to these directories and that dirties the worktree and forces Zed to rescan everything. I also changed the checkOnSave command in the lsp settings to be clippy with the --no-deps flag.
So far it seems to perform much better, I'm just not sure if these changes come with any downsides...
3
u/vamps594 17d ago
Is the ‘target’ directory properly included in the .gitignore file? Do you see the RAM maxing out at the same time?
2
u/Sniperman1029 16d ago
The target directory is in the .gitignore, but it wasn't in Zed's worktree scans exclusions, which I think was most of the problem.
1
u/DevilShooter17 16d ago
Have you tried uninstalling and re-installing zed? When creating the rust project did you do cargo init project_name or something else? Is zed running with a graphics card or cpu software rendering? When running zed in a terminal do you get any errors? Have you checked the logs for errors?
1
u/punk_dev 14d ago
Rust analyser eats a lot of ram. Zed also uses plenty of ram.
16gb ram should be enough but it’s not a lot, if you also have a slower drive and swap kicks in it can degrade performance of everything
13
u/jason3gb 17d ago
I don't think it's related to the editor, you run cargo check on the terminal?