Skip to content
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: gopls often becomes unresponsive when working on packages with long compile times #46590

Closed
firelizzard18 opened this issue Jun 5, 2021 · 8 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@firelizzard18
Copy link
Contributor

firelizzard18 commented Jun 5, 2021

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

$ go version
go version go1.16.4 linux/amd64
$ ~/go/bin/gopls version
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="REDACTED/.cache/go-build"
GOENV="REDACTED/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="REDACTED/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="REDACTED/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="x86_64-pc-linux-gnu-gcc"
CXX="x86_64-pc-linux-gnu-g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1769211522=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have attached a very basic GTK program that uses github.com/gotk3/gotk3. Clean compilation of gotk3 takes quite a while. I am using my own fork of gotk3 - whenever gotk3 has to be recompiled, the build takes quite a while.

What did you expect to see?

Actions (in VSCode, using gopls) unrelated to gotk3 resolve in a timely manner.

What did you see instead?

Once gopls triggers a build or whatever of gotk3, it is entirely unresponsive until the build is complete. For example, ctrl-clicking on an import statement will not bring up pkg.go.dev, even though that in no way requires gotk3 to be compiled.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 5, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jun 5, 2021
@findleyr
Copy link
Contributor

findleyr commented Jun 7, 2021

Hi, thanks for the report.

There are two possibilities for what is going on here: one is that gopls RPCs are getting queued up behind a slow request, and another is that your CPU sufficiently saturated to make everything slow. Based on your description of the symptoms, this sounds like the first scenario. In this case, RPC logs would be very helpful. Would you mind grabbing some logs and attaching them here? Instructions for how to do so can be found here.

I have attached a very basic GTK program that uses github.com/gotk3/gotk3

FWIW I don't see any attached program, but in any case the logs would be most useful.

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 7, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/unplanned Jun 7, 2021
@firelizzard18
Copy link
Contributor Author

firelizzard18 commented Jun 8, 2021

FWIW I don't see any attached program

GitHub won't let me attach a .go file, and Firefox crashed while I was appending it as a code section and I forgot to update the issue... Here is one of GoTK3's examples that should reproduce the issue.

I'll work on getting logs.

@firelizzard18
Copy link
Contributor Author

firelizzard18 commented Jun 8, 2021

I generated gopls.log.zip using the following settings:

    "go.languageServerFlags": [
        "-logfile", "REDACTED/Desktop/gopls.log",
        "-rpc.trace"
    ],

    "gopls": {
        "env": {
            "GOCACHE": "/tmp/go-build-cache",
        }
    },

As soon as I do something to trigger an RPC to gopls (such as opening simple.go which makes a request for code lenses), a horde of C compiler processes are spawned. These processes certainly consume a lot of power, but that didn't have a noticeable impact on my overall system performance. Once cc1 no longer appears in top, editor features driven by gopls start working again.

FWIW, I'm using Gentoo with USE=-bindist, meaning everything (non-proprietary) is compiled locally from source. So it's conceivable that go install github.com/gotk3/gotk3-examples/gtk-examples/simple performs especially badly with this setup, maybe because it's recompiling all the C library dependencies (gtk, gdk, glib, opengl, etc).

@echovl
Copy link

echovl commented Jun 8, 2021

I experience the same problem using github.com/gotk3/gotk3 with neovim + gopls. Everytime I jump to a definition related to gotk3, gopls triggers cgo compilation, which is very slow and cpu intensive.

@findleyr
Copy link
Contributor

findleyr commented Jun 9, 2021

Here is one of GoTK3's examples that should reproduce the issue.

Thanks, I'll experiment with that.

As soon as I do something to trigger an RPC to gopls (such as opening simple.go which makes a request for code lenses), a horde of C compiler processes are spawned.

Discussed this a bit with the team as I don't have that much experience with cgo. Yes, this is almost certainly related to cgo, apparently invoked during go list, which would explain the symptoms you describe.

Everytime I jump to a definition related to gotk3, gopls triggers cgo compilation, which is very slow and cpu intensive.

Hmm, I don't yet understand why this would be the case. I'll look into it.

@findleyr findleyr added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jun 9, 2021
@findleyr
Copy link
Contributor

Yeah, this is a pretty poor experience. I think it might be improved by @stamblerre's work on metadata invalidation, which should be in soon.

@echovl which neovim client are you using? I'm guessing the reason you hit a recompilation is that you jumped outside of your workspace, which at least on coc.nvim will trigger a new workspace folder in your session. It should only happen on the first jump, although the build takes so long that may be enough...

@findleyr
Copy link
Contributor

I think the best we can do here is to not become unresponsive after the initial workspace load, which means most gopls behavior continues to work in the presence of stale package metadata (even if a load is ongoing). I'm not 100% sure this will be possible, but @stamblerre's pending changes get us at least part of the way there.

Putting this in gopls/v0.7.1, as investigating this is timely.

@echovl
Copy link

echovl commented Jun 12, 2021

Yes I did notice that, after the first jump everything is responsive again, thanks for your help! @findleyr

@stamblerre stamblerre modified the milestones: gopls/v0.7.1, gopls/v0.7.2 Jul 26, 2021
@stamblerre stamblerre modified the milestones: gopls/v0.7.2, gopls/on-deck Sep 9, 2021
@golang golang locked and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants