-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
rust-analyzer tries to check all crates in vscode workspace in parallel #8631
Comments
Related to #8622, we should maybe run the initial Assuming this is just a folder with a bunch of crates in it, and not a Cargo workspace, I would probably recommend opening the specific crate folders instead of the top-level folders, at least for now. |
This sounds like we might want to provide a shared jobserver to all Cargo processes we spawn |
It's a VSCode "workspace" containing around 40-50 individual Cargo crates, but not a Cargo workspace. I've turned off |
@jonas-schievink that's a good idea, but I don't think it would really solve the usability problem with such a large workspace. I.e. presumably you want to work on one or two crates out of the 50, but you still have to wait for all 50 to be built for everything to work. |
In my specific case that'd be fine, but in general I agree it would make sense for projects with opened files to be built first. |
Although actually the initial check shouldn't take that long, since we don't actually compile the crates. But flycheck (check on save) should really be done lazily only for crates that are actually opened, if we're not doing that already. |
Still, I would tend to say that probably support for such huge workspaces isn't really a goal right now (but maybe @matklad and @jonas-schievink disagree). |
I don't think we can make wins here with laziness. As soon as the user invokes "workspace symbols", we'd have to process the world anyways. It feels like another case where our automated discovery of the project structure falls down, and where an explicit configuration in terms of For the time being, I suggest not fixing this issue. Long term, I think the right fix would be to, if our auto-discovery found > 5 crates, show a message to the user about the project load. |
... unless we don't do that for crates that aren't loaded currently (that was what I was imagining). Of course that would make it very non-obvious what will be covered by workspace symbols / find references etc., which I guess is kind of what you refer to in #8622. It seems to me what we really want would be a nice way for the user to dynamically control which crates are loaded and which aren't; you're probably right that doing it completely lazily/implicitly is also not a good user experience. Maybe this is best left to the client. |
Yeah, IntelliJ has unloaded modules thing for that: https://www.jetbrains.com/help/idea/unloading-modules.html#7a53c16f. IIRC, it was added because IJ struggled with JetBrains own monrepo :D |
FWIW, every other feature of the extension that I've tried works snappily in my large workspace, including find references, workspace symbols, etc. It's only the spawning of 200 rustc processes that have caused me a problem. (Maybe find references etc only have a partial view of the "world" though since I disabled |
Ahh, wait, I think the problem is not the initial cargo check (we do that sequentially) but the |
That aligns with my experience. My laptop didn't start to melt as soon as I opened the workspace, but a while later — probably shortly after I saved a file. |
I think sequential / less parallel However, another thing that could help would be instead of checking the entire workspace to only check the current crate on save and offer some extra command or a low-prio background task to check the whole workspace. |
This would only work if it's a Cargo workspace, right? Because rust-analyzer is actually running a separate |
Ahh, I didn't know that. 💡 |
Is there a good reason not to run I sometimes encounter situations where |
That's not related to this issue - this issue is about r-a running |
I'm thinking of working on this issue, but I'm wondering: If the issue is that we're rechecking every cargo-workspace in the vscode-workspace on each save, shouldn't we change that so that we detect which cargo-workspace the given saved file was in, and only recheck that cargo-workspace? |
If another cargo workspace depends on the changed crate as deoendency, that other cargo workspace needs to be recompiled anyway. If it doesn't, |
That doesn't seem to align with @jbg's experience, unless he has a large amount of interdependent crates inside his editor-workspace. edit: Also, technically crates only need to be rechecked if pub items on the dependency boundary changed. Which should be pretty rare when working on them independently. |
My crates are mostly not interdependent. I gave up on using rust-analyser with vscode some time ago so can't comment on whether this still happens in the latest versions. |
I think @jbg's problem is at startup and not while editing files. The fix would be to invoke all |
According to this comment that is not the case |
I would like to be able to limit the check to currently open crates on save - in a big workspace working on anything imported by a bunch of other stiff is unnecessary painful - checking on saving take a long of time (during which I can't run tests because of a lock on the build directory) and I don't really care how other crates are affected until I decide to start working on them. |
What do you mean by "currently open crates"? Crates that are in your vscode workspace? Only crates that have files open in an editor? |
In my case it's crates that have open files in vim. |
Are those crates part of a cargo workspace, or just all open in vim? |
Mostly belong to the same workspace, but then there's two separate crates that define their own workspaces in order to avoid messing with feature unification. It would be enough just to deal with the workspace though. |
I suspect the workspace may be where the target dir locking is really showing up. Have you tried disabling the cargo workspace? |
Yes, pretty much.
Not really an option. There's a bunch of dependencies and workspace allows to share compilation results, there's feature unification and some other stuff. |
So essentially what you want is a way to pass |
I think this would do the trick, yes. Optionally with |
Okay. I think that's kind of outside the scope of this particular issue, which is about vscode workspaces, not cargo workspaces. There is an option to set the Otherwise, consider opening a new issue for what you need. |
So there is currently no way to manually limit what crates in workspace are checked? The workaround as mentioned before is to open each crate in its own vscode window, which is not ideal. Maybe something like a Really missing those type hints! |
Glad to see some discussion around this, I'm experiencing this a lot lately, I've disabled rust analyzer because of it. Perhaps I should specify the workdir with a finer granularity. |
The original reported issue shouldn't necessary be a problem anymore I think? (unless there are 50 workspaces, not just crates) |
After installing this extension for the first time, and shortly after opening a VSCode workspace with around 40-50 crates in it, my laptop becomes completely unresponsive.
Investigation shows around 200
rustc
processes running.rust-analyzer
seems to be runningcargo check
on every one of the crates in my workspace at the same time, regardless of how many crates there are and how many CPUs I have.After
killall rustc
I am able to use my computer again, but when working in the workspace the problem periodically recurs.Is there a way to limit how many
cargo check
processes will be run at a time? Could this default to something based on the number of CPUs the system has?The text was updated successfully, but these errors were encountered: