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

Closed
tonimelisma opened this issue Dec 12, 2020 · 22 comments
Closed

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

tonimelisma opened this issue Dec 12, 2020 · 22 comments
Labels
gopls/performance Issues related to gopls performance (CPU, memory, etc). gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@tonimelisma
Copy link

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

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

Hey @hyangah here's a trace.

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

@stamblerre
Copy link
Contributor

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

@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

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

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

@tonimelisma
Copy link
Author

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

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

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

@stamblerre
Copy link
Contributor

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

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

@stamblerre
Copy link
Contributor

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

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

"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

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

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

@tonimelisma
Copy link
Author

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 Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 6, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jan 6, 2021
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Jan 6, 2021
@stamblerre
Copy link
Contributor

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 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

@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.

@mrjrieke
Copy link

mrjrieke commented Jun 3, 2023

I think this may in fact be fixed at last (for me at least). Re-enabled Language Server in vscode. I am on latest version go gopls available to me anyways:
golang.org/x/tools/gopls v0.12.1
golang.org/x/tools/gopls@v0.12.2 h1:s4mznBqCHVHeuTYjxGYJhsW3Wp4FYon8YAqiJlwlpTY=

I now have a pleasant debugging experience in the project I was trying to develop in vscode that prior caused my machine to brick.

Thanks for all the hard work that went into gopls to improve the performance.

@findleyr
Copy link
Contributor

Thanks @mrjrieke.

I think this is no longer actionable: there is a high initial cost for the cgo build (same as you would experience from the command line), but after that things should be fact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/performance Issues related to gopls performance (CPU, memory, etc). gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

5 participants