-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: reduce CPU usage #36942
Comments
History on this in #34569 |
You could also be a bit smarter about what characters the user is typing. If the user is in the middle of typing an identifier or a string, it's unlikely that typechecking at every keystroke is going to be useful. However, if right after an identifier they type This doesn't have to be a binary decision, though. There could be a heuristic based on the time between keystrokes and the characters being typed, for example. |
Just to also note that I'm particularly seeing issues when |
I imagine we are going to end up with two type checking modes. We will have the heavily debounced (~500ms) full type checking for diagnostics, and we will have the tricksy minimal type checking used for synchronous operations like completion. The three main minimal type checking tricks I've seen discussed are:
|
I would even argue that not all diagnostics should run at the same rate (say, muir's 500ms). Some analyses (particularly in staticcheck) are much more expensive than others, and also point out larger bugs than what can be affected by typing 5 characters. A simple differentiator could be those analyses that work purely on the AST, and those that rely on an IR (go/ssa, staticcheck's IR). Building the IR form is an expensive operation. |
Is there potential to only run on save instead of on keystroke? |
No, the model of |
Writing this down to make a note of it: @heschik and I discussed continuously profiling |
Some additional ideas that came out of today's meeting: Before v1.0Separate diagnostic publication for the package of the file being modified from diagnostic publication for other packages in the workspace. This will reduce the appearance of the latency of diagnostics as you code, and it will allow us to debounce the diagnostics only for the other packages, which could reduce CPU usage. After v1.0Separate diagnostic publication for parse / type-check / analysis errors. This will allow us to debounce type-checking and analysis diagnostics without affecting the latency of parse diagnostics. The only complication here is that this will change our diagnostic caching model, unless microsoft/language-server-protocol#1088 is resolved before we implement this. |
Change https://golang.org/cl/257378 mentions this issue: |
I do not consider cpu load on key stroke an issue. But I start experience constant cpu load when I do nothing. If I restart VSCode then load is 0%after some time like an hour or so it starts consume CPU again and I have restart again. |
What is it about gopls that is so CPU intensive anyhow? I don't even know where to start, but every time I try and run it, I can't have my laptop in, well, my lap. I have to have a pillow or something to insulate me from the heat that my CPU emits. Here's a typical look where it's using up 50% of my CPU when I'm not even typing, and it seems to not be able to get itself out of this state without restarting gopls, and then I have maybe another 10min or so before it starts burning a new hole in my clothes.
|
The CPU costs of the initial workspace load and the per-keystroke reactive work should now both be dramatically reduced at master, and in the upcoming v0.12.0 release. Closing this now. |
gopls
hogs the user's CPU when they are typing quickly, as it starts type-checking on every keystroke. We should debounce requests or otherwise reduce the frequency of type-checking as a user is editing their file.The text was updated successfully, but these errors were encountered: