-
Notifications
You must be signed in to change notification settings - Fork 11
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 node process goes berzerk, takes 100% CPU when I build in a separate window #96
Comments
In addition, chokidar actually does seem to do quite a bit of activity when I do |
Rust registers watcher for all *.rs files in all directories within the project basically:
There is only one *.rs file ( I could experiment with overriding the pattern and checking if it still reproduces but I would need a better way to reproduce because here building takes very short time and I don't see a major increase in CPU usage. Also the build directory takes just ~300MB here. Also
By default patterns from those global ST settings are ignored:
But note that ignoring doesn't mean that the directory won't be watched. It just means that any matching file changes will be filtered out and won't be reported to the LSP server. If the main watch pattern includes those then the OS-specific file watching implementation will likely still watch those and might cause higher CPU usage. It would have to be verified whether that's the case though and it also can differ per OS. |
As you can see in the screenshot, rust-analyzer.exe is taking up little or no CPU during this time. All the CPU cost is chokidar (the watcher). So the problem is not probe.rs, it's the directory as a whole. I think it would make sense to put target into "folder_exclude_patterns". However, if Chokidar is expending significant resource usage even on the already excluded folders such as |
Looking, I find chokidar has a documented "ignored" option in its options structure. Looking, I find LSP-file-watcher-chokidar has an "ignores" option in its options structure which gets translated to chokidar "ignored". It sounds like these flags should be enough to prevent the behavior I am trying to avoid (heavy CPU usage from chokidar watching unimportant directories). I am not familiar with the stack but looking at the LSP-rust-analyzer code I do not find lsp-file-watcher-chokidar's "ignores" getting set, and based on your comment it seems you believe you are not setting such a flag. Do (lsp-rust-analyzer settings / ST global) folder_exclude_patterns get passed to LSP-file-watcher-chokidar "ignores"? If not, could they be? |
You can try yourself putting
Base LSP package creates the watcher in: https://github.com/sublimelsp/LSP/blob/0d149265408824b73184709619af4497d9044650/plugin/core/sessions.py#L1492-L1493 If |
As I've mentioned before, setting |
Okay, so there are a few things going on here. There are two questions I think are worth asking:
Talking about question 1: Sublime Text has three different ignore settings.
My "expected behavior" (in addition to including target/, and maybe pkg/ and node_modules/ in the ignore defaults) is that you should be passing folder_exclude_patterns and index_exclude_patterns to Chokidar to be ignored. Using my configuration as an example, I have .hg in folder_exclude_patterns, but I have target/ in index_exclude_patterns but not folder_exclude_patterns (because I don't want it to track those files, but I might occasionally want to inspect a build product in the sidebar). Question 2— I will try testing putting target/ in folder_exclude_patterns and see if anything changes. If the problem persists I will file that bug on chokidar because I think there are ways they could handle this correctly regardless of OS. |
That sounds very optimistic :) Its readme states:
The pattern that rust-analyzer chooses to watch is But feel free to create issue there to discuss it. |
BTW. Maybe you can tell rust to create build files outside of the project directory? Then you could workaround the issue that way. |
I have a rust project that uses wgpu. WGPU results in the
target/
being very very large, like 4GB even though the executable is much smaller.I have noticed whenever I do a
cargo.exe run
orcargo.exe build
on this project in a terminal window, if I have Sublime Text open, it suddenly slams to 100% CPU and stays there for some time. This causes problems for the build, which is noticeably slowed down by the Sublime Text CPU peg, as well as for my program, as it has a very low framerate right after it opens (due to the CPU being taken up by Sublime). If I do "LSP: Disable Language Server" before I do the build, I do not seem to see this problem. My Rust helper plugin is preventing me from running Rust.If I have Task Manger open, I see basically all of this stems from a nodejs subprocess of Sublime Text:
If I look in Process Explorer, I see the problematic node is executing something called "lsp-file-watcher-chokidar", which I am told is a common helper for sublime lsp for watching for file changes.
I believe that rust-analyzer has spawned this chokidar to check for .rs files changing, but it has failed to configure the
target/
directory to be ignored. Therefore, when my build starts changing many files rapidly insidetarget/
, it does a lot of unnecessary work.Expected behavior: Because rust-analyzer is designed to assist with Rust, it should predict the
target/
directory exists and configure chokidar to ignore it by default. In general it should be possible to configure lsp-rust-analyzer to ignore build artifact directories liketarget/
,pkg/
or (for wasm-bindgen projects)node_modules/
.Configuration: I am on Windows 10 Build 19045. I have Rust 1.69.0, Sublime Text 4143, LSP v1.23.0, LSP-rust-analyzer v1.3.1, LSP-file-watcher-chokidar v1.0.2. My settings contains
Without
index_exclude_patterns
, Sublime Text does its own chugging during the build, but with this setting added it acts normal.I also tried adding this to the lsp-rust-analyzer settings and restarting:
But it had no effect on the problem.
The text was updated successfully, but these errors were encountered: