Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Extension causes high cpu load #2461

Closed
tonyghita opened this issue Apr 23, 2019 · 12 comments
Closed

Extension causes high cpu load #2461

tonyghita opened this issue Apr 23, 2019 · 12 comments

Comments

@tonyghita
Copy link

  • Issue Type: Performance
  • Extension Name: Go
  • Extension Version: 0.10.0
  • OS Version: Darwin x64 17.7.0
  • VSCode version: 1.33.1

ms-vscode.Go-unresponsive.cpuprofile.txt

@tonyghita
Copy link
Author

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tonyghita/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tonyghita/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gv/vdmq3_l541b_0lq_ds37xslnzgdpkw/T/go-build045906030=/tmp/go-build -gno-record-gcc-switches -fno-common"

@tonyghita
Copy link
Author

The Go portion of settings.json:

{
    "go.formatTool": "goimports",
    "go.installDependenciesWhenBuilding": false,
    "go.useLanguageServer": true,
    "go.vetOnSave": "off",
    "go.lintTool": "staticcheck",
    "go.lintOnSave": "file"
}

@tonyghita
Copy link
Author

tonyghita commented Apr 23, 2019

The settings I had don't seem to make sense. I read through the installation instructions of gopls, ensured gopls was installed, and replaced my existing configuration with the provided configuration.

"go.useLanguageServer": true,
"go.alternateTools": {
     "go-langserver": "gopls"
},
"go.languageServerExperimentalFeatures": {
    "format": true,
    "autoComplete": true,
    "diagnostics": true,
    "goToDefinition": true,
    "hover": true,
    "signatureHelp": true,
    "goToTypeDefinition": true,
    "documentSymbols": true,
},
"go.buildOnSave": "off",
"go.vetOnSave": "off",
"[go]": {
    "editor.snippetSuggestions": "none",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
},
"gopls": {
    "enablePlaceholders": true, // add parameter placeholders when completing a function
    "enhancedHover": true,      // experimental to improve quality of hover (will be on by default soon)
}

The editor and plugin seem to be pretty happy now.

@ramya-rao-a
Copy link
Contributor

Thanks for that note @tonyghita

With the latest version of the extension most of the above are not needed.
Can you try removing all the above except "go.useLanguageServer": true, reload your VS Code window and see if you see high CPU usage?

@tonyke-bot
Copy link

I have the same issue with "go.useLanguageServer": true
If I disable languaguServer, everything is good except those go modules project. I highly doubt that this feature is causing the crash.

FYI
image
image
ms-vscode.Go-unresponsive.cpuprofile.txt

@lloiser
Copy link

lloiser commented Apr 24, 2019

I had the same problem. Even copying the recommended settings from https://github.com/golang/go/wiki/gopls#editors-instructions did not work.

Eventually I fixed it by:

  • set "go.useLanguageServer": false
  • reload vscode
  • get prompt to install and use the gopls language server
  • reload vscode

I have not installed gopls previously, so maybe there is an issue with the detection of gopls?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Apr 24, 2019

Thanks for sharing what worked @lloiser

@THaGKI9 Can you try the steps that @lloiser shared above and see if that helps?

@lloiser and anyone else who are able to fix the situation with the above steps:
Can you describe what the status of your settings were before the high cpu usage problem?
I'd like to replicate the scenario to come up with a fix, because it looks like multiple users are seeing the issue after the latest update

@tonyke-bot
Copy link

@ramya-rao-a

Following @lloiser 's instructions,
I set "go.useLanguageServer": false and reload the vscode.
But I don't get prompt to install the gopls language server and I try to manually install gopls with

$ go get -u -v golang.org/x/tools/cmd/gopls

After installing gopls, I restart vscode with goLanguageServer enabled and the problem is fixed

@lloiser
Copy link

lloiser commented Apr 24, 2019

@ramya-rao-a these are my settings that worked very well with the previous version 0.9:

{
    "go.autocompleteUnimportedPackages": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.toolsGopath": "/Users/lloiser/go_tools",
    "go.lintFlags": [
        "--config=${workspaceRoot}/scripts/revive.toml"
    ],
    "go.lintTool": "revive",
    "go.useLanguageServer": false,
    "go.vetOnSave": "off"
}

After updating to 0.10 I only changed

    "go.useLanguageServer": true,

which resulted in the high cpu...

I did not have gopls or any other language server installed previously.

@tonyghita
Copy link
Author

tonyghita commented Apr 24, 2019

@ramya-rao-a

With the latest version of the extension most of the above are not needed.
Can you try removing all the above except "go.useLanguageServer": true, reload your VS Code window and see if you see high CPU usage?

I removed all go-related settings except "go.useLanguageServer": true, and everything seems to work fine. I do not get the high-CPU issue.

At this point I wonder if the issue was actually that gopls was not yet installed (I happened to be working off a fresh installation of MacOS). I was not prompted by the extension to install any tools. I installed gopls via go get.

@ramya-rao-a
Copy link
Contributor

Thanks for the sequence of steps @lloiser, I was able to replicate the issue
@tonyghita Your notes helped as well

I have pushed a fix and released an update (0.10.1) which will have the fix.

Thanks for reporting and your patience and for helping me figure out the issue!

@tonyghita
Copy link
Author

@ramya-rao-a very much appreciate your leadership on this plugin, thank you!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants