go: x/tools/gopls: high CPU & memory for minutes in "Saving foo.go: Getting code actions from "Go" ..."

What version of Go are you using (go version)?

Go 1.19.4 gopls 0.11.0

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

darwin/arm64 Visual Studio Code => ssh to linux/amd64

What did you do?

I’m trying to become a Visual Studio Code + gopls user, trying to break my emacs habit. I use Visual Studio Code on a Mac over SSH to a Linux server, where gopls/etc runs remotely.

A good fraction of the time when I save in VS Code, I see:

Screenshot 2023-01-09 at 11 44 22 AM

For minutes.

Meanwhile, gopls is using 4-8 GB or more of memory and using tons of CPU.

perf top says:

Screenshot 2023-01-09 at 11 44 54 AM

What did you expect to see?

Faster, I guess.

What did you see instead?

Slower than it seems it should be.

Is this a bug?

I don’t know how to go about debugging gopls.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 8
  • Comments: 20 (12 by maintainers)

Most upvoted comments

I don’t want to jinx it, but so far so good! 🤞

@adonovan let’s close this after we cut the release candidate containing our fix. Then it will be easy for people to test, and comment if they can still reproduce the freezing.

I am 92% sure this is a dupe, and now fixed.

Hmm, that’s… unfortunate.

The likely cause of that is that gopls has loaded a bunch of packages (intermediate test variants) for e.g. a references request, and holds on to them until a restart. This particular behavior will be fixed in the next gopls release.

FWIW, in my experience, this can occur when gopls gets into a bad state. It is responsive (enough) working on a project, it gets unhappy, and then saving fails until you kill and restart it.

For others experiencing this, you can get past it in a pinch by using the VSCode command palette to do “Save without formatting”. And then restarting. 😕

Apologies for commenting on a closed issue, but I’m getting this same issue and it’s completely crashing my macbook unless I kill the go or gopls process manually. Loving learning Golang but this issue is a bit frustrating. Thanks in advance for looking at this issue.

Details: go version go1.21.4 darwin/arm64 M1 Pro 16GB - Ventura 13.6 (22G120)

Oof, sorry about that @joel-rieke

It sounds like there may be something we don’t understand going on here, but we are in the process of making major changes to the way gopls executes (https://go.dev/issue/57987), and my hope is that it makes all of these problems go away.