-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: imports extremely slow with large module cache #32750
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
Comments
Is there a command I can run on my machine to demonstrate if I am experiencing this? I only have a 250MB module cache, but imports take 30-45s on my machine at least. I do have a likely somewhat larger than normal repo with many packages in it, however. |
Do you see this kind of latency when you run |
@bmhatfield Run |
I took a file that was having difficulty performing imports (30-45s in vscode "running save participants") and never actually completing the imports. I edited it into a state where VSCode reliably is sluggish and fails to perform imports/formatting (by deleting 3 import lines).
|
Do you see similar latencies with other |
Jump to definition: 2-3s latencies, with a blue "processing bar" that moves across the top of the window. |
Wow, that's a very strange range of latencies. Definition should definitely feel instant as well. I would have expected every feature to be slow rather than some, and then even so, it seems like go-to-definition is still faster than imports. Do you mind sharing a full |
Happy to - should we migrate this conversation to #32360, given that I am not experiencing the "large module cache" issue? Or prefer here still? |
Purely anecdotal, but I have also experienced normal gopls response times for everything but goimports. (I fear I am AFK for a while, so can’t help reproduce/debug.) |
Either is fine as these all seem to be general imports related issues, so whichever you prefer. We are in the process of adding a lot more tracing and debug information, so it's possible we won't be able to get to the bottom of the issue until all of that is submitted. |
Hrm. There appears to be no output in the |
Oh, I'm sorry I forgot to mention that you should add |
Apologies, that's on me. You've mentioned this in other issues I'm active in. {gist link removed} In this particular case, I restarted VSCode before capturing the log, and things were "faster" at 8.5s for imports, though the imports never actually materialized in VSCode (ie, the code to be imported was still undefined symbol errors). I also code navigated towards the end of the log but it wasn't as slow in this particular case as it sometimes is, though you can see other timings are a bit all over the place. I am happy to continue gathering logs as needed. EDIT: for reference:
|
Thank you for sharing. The times here are really strange - it seems like imports starts out working at ~1 second as expected, and then somehow gets to 8 seconds, which causes the subsequent requests to stall (there is no reason for Can you try setting the |
We don't use cgo directly, I also believe that none of our dependencies use cgo. |
Added an updated log to that gist. (Gist link removed because it appears to contain somewhat sensitive code - @stamblerre is there a way to send you this more privately?) I believe I successfully rebuilt |
@bmhatfield: If you are willing to share these logs with me, I am reachable on the Gophers Slack (https://invite.slack.golangbridge.org/) or you can send me an email at [email protected]. Is anyone else experiencing a similar issue? It would be useful to see if this is a common problem or an issue specific to your setup. I have sent out a CL to add additional logging for |
I have same issue. Gopls is frozen when I try to add new import. In other cases it works fine. |
@s-kostyaev: Are you able to share your |
Ok, I'll try to reproduce it on non sensitive data. |
gopls-stderr.log |
Can you sync to master ( |
Thanks. It stops freezing. And panic is also fixed. |
@stamblerre Just checking in here - is there further information I can gather to be helpful? I believe you mentioned that there's additional logging/tracing that will land soon - is that ready for me to gather more data with? |
I did submit a change that turned the imports debug logging on by default: https://go-review.googlesource.com/c/tools/+/184198. |
Actually, @bmhatfield, can you share logs using imports with the latest version of |
Chiming in here to say I've been staying reasonably current on |
@heschik @suzmue - any update on this? Thanks |
We have started reusing the imports resolver in gopls (https://golang.org/cl/184921) and added some caching of packages in the module cache (https://golang.org/cl/186301), which both work to speed up imports when there have been no go.mod file changes. A new caching design is currently being implemented to avoid repeat work of scanning the module cache. Pre-warming of this cache has not been implemented yet. |
Thanks. See some benefits here as a result of https://golang.org/cl/184921 and https://golang.org/cl/186301.
This will also help. However, for Vim users (via whatever plugin) this will also likely become something of a pain. Because Vim users typically start/stop Vim regularly, especially when used from the terminal. Hence, if So any pre-warming will, I suspect, need to go hand-in-hand with ensuring the socket-based communication with |
Will continue conversation in #34111 |
Sounds good. @myitcv: Do you feel that this issue has been resolved enough that we can close this? (We can track future imports improvements in other issues.) |
I think the final piece in the puzzle is probably:
But I think that only makes sense post #34111 for the reasons laid out in that description. So yes, can probably close this if we create a follow up issue for the pre-warming of the cache, an issue that is contingent on #34111 |
Sounds good. Closing this and filed #34115 to track pre-warming the cache. |
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?
The issue I keep tripping across is making refactoring changes that, for example, rename variables. If I fail to rename all instances of the variable (perhaps I've copy-pasted some code from somewhere), there's a chance I've left behind a selector expression with the old variable name... which is now treated by
imports
as if it were a qualified identifier for a package that has not yet been imported.Like #32726,
imports
then heads off into the module cache searching through all potential matches. With a 5GB module cache, this is not a quick operation.I think
imports
should:go.{mod,sum}
reachable from the main module changesYes, this will cause possibly stale results in the case that another main module causes changes in the module cache, but I think that's a sacrifice worth making for the general speed of
imports
.What did you expect to see?
Instant responses to
imports
-based format-on-save.What did you see instead?
~10sec delays.
cc @stamblerre @ianthehat @heschik
The text was updated successfully, but these errors were encountered: