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: slow packages.Loads with cgo #43560

Open
tonimelisma opened this issue Dec 12, 2020 · 20 comments
Open

x/tools/gopls: slow packages.Loads with cgo #43560

tonimelisma opened this issue Dec 12, 2020 · 20 comments

Comments

@tonimelisma
Copy link

@tonimelisma tonimelisma commented Dec 12, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go 1.15.6
  • Run gopls -v version to get version of Gopls if you are using the language server.
    • v0.6.0-pre1 and v0.5.5
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • Version: 1.53.0-insider
      Commit: 76436a4d43566cd313629799e2ec51b4d00caa64
      Date: 2020-12-11T17:46:02.603Z
      Electron: 11.0.3
      Chrome: 87.0.4280.67
      Node.js: 12.18.3
      V8: 8.7.220.25-electron.0
      OS: Darwin x64 20.1.0
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.19.1 as well as go-nightly v2020.12.814
  • Run go env to get the go development environment details
    • GO111MODULE=""
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/home/toni/.cache/go-build"
      GOENV="/home/toni/.config/go/env"
      GOEXE=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="linux"
      GOINSECURE=""
      GOMODCACHE="/home/toni/go/pkg/mod"
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="linux"
      GOPATH="/home/toni/go"
      GOPRIVATE=""
      GOPROXY="https://proxy.golang.org,direct"
      GOROOT="/home/toni/sdk/go1.15.6"
      GOSUMDB="sum.golang.org"
      GOTMPDIR=""
      GOTOOLDIR="/home/toni/sdk/go1.15.6/pkg/tool/linux_amd64"
      GCCGO="gccgo"
      AR="ar"
      CC="gcc"
      CXX="g++"
      CGO_ENABLED="1"
      GOMOD="/home/toni/go/src/github.com/davidbyttow/govips/go.mod"
      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-build840047076=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"go.coverageDecorator": {
"type": "gutter"
},
"go.coverOnSingleTest": true,
"go.coverOnSingleTestFile": true,
"go.coverageOptions": "showUncoveredCodeOnly",
"editor.codeActionsOnSave": null

Describe the bug

Every now and then, for months now with various Go extensions and Go nightly extensions, when I save a Go file, VS code stalls for a couple of minutes saying "Getting code actions from Go"

The stall is about two minutes. As you can see from the screenshot, editor.CodeActionsOnSave is null.

Steps to reproduce the behavior:

  1. Edit go file
  2. Save go file
  3. Every 20th time VS code hangs for a few minutes, saving the file

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Screenshot 2020-12-12 at 21 48 47

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 12, 2020

If you want to disable code actions, I think the right syntax is "editor.codeActionsOnSave": {}. If you'd like to investigate the underlying issue here, please share a gopls log: https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs.

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 20, 2020

Hey @hyangah here's a trace.

vscode_hangup.txt
Screenshot 2020-12-21 at 0 02 58

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 21, 2020

It looks like your log may be incomplete--I would expect it to start with an initialize request. Do you mind sharing a complete log starting from the initialization?

Also, I notice that there are 2 extensions listed in the pop-up here--does disabling the "GitHub Pull Requests and Issues" extension fix the problem?

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 22, 2020

@stamblerre did you read the attached text file as well? It covers the whole period of the hangup, not all they way from the start of vs code. Isn't that enough?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 22, 2020

Yes, I did read that file, but gopls logs useful debugging information at start-up, which is why it would be best to have a log starting at initialization. If that's not possible, you can run gopls -rpc.trace -v check path/to/file.go in your VS Code workspace root.

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 22, 2020

@stamblerre here's one all the way from the beginning
Untitled.txt

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 22, 2020

On further usage, right now, when I e.g. run the tests, the Go extension starts compiling the program. If I cancel the tests, it doesn't stop the compilation, it keeps running on the remote server. Now every time I save a Go file it stalls for 2 minutes as it's waiting for the compilation to end.

Edit: actually, whenever I save a file, it starts compiling the whole program. If I save numerous time one after another, for each save, it starts the whole process of compiling the program. It's a cgo program.

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 28, 2020

Hey @stamblerre any updates on the topic? I suppose we are still not "waiting for info"? This makes VS code impossible to use for me

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 28, 2020

Apologies, I must've missed your response. Does setting "go.useLanguageServer": false resolve the problem temporarily while we investigate?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 28, 2020

On further usage, right now, when I e.g. run the tests, the Go extension starts compiling the program. If I cancel the tests, it doesn't stop the compilation, it keeps running on the remote server. Now every time I save a Go file it stalls for 2 minutes as it's waiting for the compilation to end.

Edit: actually, whenever I save a file, it starts compiling the whole program. If I save numerous time one after another, for each save, it starts the whole process of compiling the program. It's a cgo program.

Ah, I see it's also related to running the tests. Does it work if you don't run the tests, or are the saves still slow then?

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Dec 28, 2020

It's unrelated to testing, although "Build on save" is set to package, the default value

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Dec 28, 2020

That setting doesn't actually apply when the language server is enabled. To follow up on some of my earlier questions:

  • Were you able to disable code actions by setting "editor.codeActionsOnSave": {}?
  • Does disabling the "GitHub Pull Requests and Issues" have any effect?
  • Does setting "go.useLanguageServer": false resolve the problem temporarily while we investigate?

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Jan 6, 2021

Hey @stamblerre still seeing this issue.

  • Disabling Github Pull requests doesn't have any effect
  • Setting language server false does indeed help
  • "editor.codeActionsOnSave": {} indeed does remove the stalling yet on saving it does run gofmt (or similar) on my file

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jan 6, 2021

"editor.codeActionsOnSave": {} indeed does remove the stalling yet on saving it does run gofmt (or similar) on my file

You can set "editor.formatOnSave": false to disable formatting.

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Jan 6, 2021

That's fine. The big issue still is that it tries to build my Go project each time I save the file. Being a cgo project, that takes several minutes.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jan 6, 2021

Is this still happening with "go.useLanguageServer": false? If so, then you can try setting "go.buildOnSave": "off".

@tonimelisma
Copy link
Author

@tonimelisma tonimelisma commented Jan 6, 2021

Hey @stamblerre please see my previous comment 6 hours ago, in which I explained that it is indeed not happening when I set go.useLanguageServer false.

@stamblerre stamblerre transferred this issue from golang/vscode-go Jan 6, 2021
@stamblerre stamblerre changed the title 2 minute stall on "Getting code actions from "Go"" every 20th save even though actions disabled x/tools/gopls: slow packages.Loads with cgo Jan 6, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jan 6, 2021
@stamblerre stamblerre removed this from the Unreleased milestone Jan 6, 2021
@stamblerre stamblerre added this to the gopls/v1.0.0 milestone Jan 6, 2021
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jan 6, 2021

Thank you for the clarification. I've transferred and retitled this issue, and we will try to investigate it more thoroughly when possible (likely not in the next month). In the meantime, we hope the workaround of disabling the language server will be sufficient.

@mrjrieke
Copy link

@mrjrieke mrjrieke commented Feb 5, 2021

I've noticed huge lag/deadlock with gopls as well and initially attributed it to a large package set (some recent work was done for that, but still seeing intermittent deadlocks now). But perhaps this has bearing as well since my project I believe relies upon some c-libraries. These periodic machine hangs where I see gopls pegging my cpu at 290% for 10-20 seconds at a time make me want to just turn it off.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Feb 5, 2021

@mrjrieke: Can you please open a separate issue so that we can investigate your problem separately? Please include the information requested in the troubleshooting guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants