Rust-analyzer becomes slow with larger crates

What do you do when this happens? What settings to change?

I have lot of macros and rust-analyzer became quite unresponsive, I have to wait for 20-30 seconds for it to finish and show errors and warnings.

cargo check probably simply takes that long for your project. There is nothing rust-analyzer can do about that. Most errors and warnings are provided by rustc through cargo check. Only a couple, like syntax errors, are built into rust-analyzer.

cargo check is much faster, so here is the routine for me in neovim:

  • split the window and run bacon
  • code
  • jump to errors/warnings/... via nvim-bacon

BTW rust-analyzer seems to detect errors only for opened files, but cargo check (therefore bacon) can detect errors in the entire project (including members in workspace). Correct me if I'm wrong :slight_smile:

Yes, it's cargo check actually. I have i9-9900K and 32GB of memory, so that's not bad I guess. It seems that some kind of errors are specially bad for performances and this happens usually when I do some bigger refactoring and break things at many files.

I definitely see diagnostics for unopened files when using something like :Telescope diagnostics or folke/trouble.nvim.

however:

  • By default nothing indicates the existence of any diagnostics for unopened files afaik.
  • I have been seeing something where rust-analyzer apparently clears the diagnostics after reporting them on startup, so I don't get diagnostics until the second cargo check, I thought it was a vim issue but it seems to be the case across editors, and affects both opened and unopened files.
1 Like

You're right!

Yeah, and I love the summarized infomation bars bacon shows, because it fixes the problems you raise somehow.

Indeed. Rust-analyzer native errors are only calculated for open files to improve performance. Errors produced by cargo check are shown for all files.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.