-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/gopls: "stuck" at 100% CPU #34569
Comments
Did you investigate to see if it's really stuck somewhere? Maybe staticcheck is just spending a lot of time doing extra work for some reason. |
Not looked in detail as yet. Raised the issue to see whether others are seeing problems as much as anything. |
Not sure if I'm doing something wrong, but gopls seems to get completely stuck using %400+ CPU every few minutes for me during regular development, I have to keep killing it. I'm using |
What strikes me as odd are the many goroutines doing work in My suspicion is that SSA construction is taking a fair amount of time, and gopls keeps spawning more of it, not waiting for completion. But that's just a guess. |
I think @dominikh is right. Every file change triggers a new diagnostics run, cancelling any previous in-progress diagnostics. As discussed in slack, the rub is that go/analysis doesn't support cancellation, so you can end up with multiple running at once. gopls has its own go/analysis driver, so it could at least check the context before starting each pass. |
Adding my very rudimentary analysis from Slack:
I've retitled to confirm this is not a problem with Could we separate the calculation of parse, type and analysis diagnostics? It seems that none of these categories should ever run concurrently in response to a change (i.e. shouldn't have two parse checks running concurrently, but ok for a parse and type check to be running concurrently), but they can (and should) run independently given the widely varying times taken to run each. Taking the example above, if Thoughts? |
I have the same issue. gopls is constantly stuck between 100% and 600% while I do nothing. If I kill It, it starts over and after a second or two, back to battery draining. It has became totally unusable for me |
Actually, my issue seems to be caused (and fixed) by what's discussed in here : #34906 (comment) |
I suspect that #34906 and the fix in https://go-review.googlesource.com/c/tools/+/201098 will deal with part of the problem. However the CPU issue will likely remain because per #34569 (comment), type checking and analysis happens on every single change to |
I've done a bit more digging here because something really wasn't adding up. The ~200ms for type checking reported in #34569 (comment) is the time taken for a full type check, i.e. all transitive dependencies. It doesn't therefore make sense that after a single change to a file in said package that a full type check happens, because The issue appears to be that making changes in any file in a package, say If instead you make changes to any file in a package that does not have test files (i.e. by definition you're changing on of the package files) then the type check is instantaneous, ~5ms. This is entirely reproducible on my machine, and visible via the Jaeger trace viewer. I think this explains the discrepancy, however I've not looked into why this is happening within |
My previous comment is accurate as of f936694. |
Further update to #34569 (comment) after some investigation with @stamblerre: The package in question, Therefore I wonder whether, given the implementation of type checking/analysis stands, i.e. limits on ability to cancel work, and working on the assumption that type checking/analysis are both are as concurrent as they can be, we shouldn't simply limit the number of concurrent type checking/analysis runs to one each. i.e. this means we will potentially collapse down type checking/analysis runs when there are fast streams of updates (in larger packages). |
I believe I am hitting this case as well. I find that it's specifically triggered when refactoring code - VSCode submitting "incomplete" code to This has been my experience on multiple versions, including the most recent at the moment |
Using VS Code remote development container, gopls at ~500% CPU (15'' MacBook Pro 2017) hangs Docker (hyperkit) indefinitely. For regular environment best workaround seems to be routinely restarting the language server. I am still amazed there aren't expletives all over this GitHub issue. |
@ermik: What version of |
The VS Code tools update command ran recently (~2-3 days ago) has pulled in
and upping the "insider" version of |
From a day of using The obvious failures came from import handling:
Thanks, Rebecca. |
Thanks for the report, @ermik. If you are able to file an issue with a repro case and a log I can help you investigate the issues that you've noticed (see https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs for information on how to capture the logs). |
Marking as v1.0.0 because this remains a big usability issue. |
@myitcv: This is only with staticcheck on, right? I'm not sure if you were there when I said this, but staticcheck will still be off by default in |
No, I ended up turning staticcheck off. Things were getting swamped simply because of the load of type checking with the 1.4MB of code in that package and many changes per second (as I typed to make changes, for example). I'll retest this against the latest |
Sorry, based on this, I had assumed that this was only relevant to staticcheck so I changed the issue title. I think you can try it with master now, it should be stable enough to check. |
I've just done a test against 0cba7a3 with partial revert of CL 214586 applied on top, in the form of CL 215239, and things are massively improved. i.e. we don't appear to suffer anywhere near the level of analysis "floods" we did before. Therefore I'm going to close this issue; we can always re-open if there are specific cases that do cause problems. Thanks for all the fixes as ever @stamblerre 😄 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
staticcheck
withingopls
govim
There is clearly extra CPU required with
staticcheck
enabled, and I see that on startup. It's just that 1 time in 5 something gets stuckA
kill -SIGABRT
stack trace andgopls
log file can be found here:https://gist.github.com/myitcv/4ef84fd1115d27f1305566647278f72e
Disabling
staticcheck
withingopls
I no longer see any problems.What did you expect to see?
Normal operation
What did you see instead?
Per above
cc @stamblerre @ianthehat @dominikh
The text was updated successfully, but these errors were encountered: