-
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: Is there a way to reduce the memory usage? #61352
Comments
Hi, do you by any chance have "staticcheck" enabled? Can you share your gopls settings? |
Yeah, the gopls setting is all the default. I didn't change anything after install it. I notice that staticcheck is enabled.
The memory problem only happens in stage1. |
@Kidsunbo sorry I meant the staticcheck analyzers integrated with gopls, via the "staticcheck" setting: https://github.com/golang/tools/blob/master/gopls/doc/settings.md#staticcheck-bool If you are using the defaults, I assume this is not enabled, unless your editor changes the defaults.
Can you share the output of |
Sure, here is the output of
Maybe it's due to I restarted my Mac. This time the process seems to be OK. It finished in just a few minutes. But is the TotalAlloc still a little high or expected? As for the profile, I didn't find it in /tmp. In addition, all the projects that trigger the problem are close-source projects in my company. I think I am not allowed to share the profile which might contain debug info or something. Sorry for that. |
Thanks @Kidsunbo. It looks like you have a medium-large workspace, but perhaps with some large packages. We have two existing bugs related to opening a package that depends on a particularly large package (#61178 and #61207). Based on the symptoms you describe, it sounds like static analysis is taking a long time. It may not take a long time now, because it successfully analyzed all your dependencies (and now those results are cached).
Profiles in general do not contain private information (they contain timing information for functions in the gopls executable). However, all we really need is the top functions, which you can inspect before sharing. If you could do this, it would be very useful:
That will output the top functions consuming CPU in gopls, during the 10 seconds that it samples. Try to catch gopls in the act of burning through CPU/memory. If you can share the results, it will tell us the root cause. |
Sure, here is the output:
|
I run the command three times, and here is the generated pb file. |
I also pprof the heap which should be more related to the problem:
|
I believe we have made progress on the runaway resource usage caused by analysis. In particular, we have reduced parallelism so that analysis should never hit the same high water mark. @Kidsunbo could you please try out the prerelease to see if it improves the situation for you?
We have ideas for how to improve the cost of analysis facts, but that is a separate issue. Also: @xiaokentrl I see you 👎ed a few comments: are you also experiencing problems with memory usage? If so, could you share what you are experiencing? |
Yeah, much better, you guys did a good job. And now there is the progress to learn about how many packages have been indexed, which is good. I think now this issue can be closed. It does not exhaust my resource. Thank you so much. |
Change https://go.dev/cl/513735 mentions this issue: |
gopls version
go env
What did you do?
I have one close-source backend project, gopls takes 20 minutes to index and the memory usage is intolerably high. For comparison, GoLand only uses no more than 5 GB and only 30 sec to finish the indexing.
The computer I use is MacBook Pro (16-inch, 2019) with 32 GB memory.
I don't know what causes this but for information, the project has some big Golang source code files with more than 400,000 LOC, which are generated by thrift. I've also tried to index the source code of k8s, it works fine and can finish indexing in seconds and the memory usage is less than 4GB.
What did you expect to see?
The memory usage could be much less and the speed could be faster.
What did you see instead?
The whole process takes so long and uses a lot of memory.
Editor and settings
All the settings are default with the default Golang extension in VSCode.
Logs
The text was updated successfully, but these errors were encountered: