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

High CPU usage when working with cgo #2598

Closed
RadhiFadlillah opened this issue Jun 25, 2019 · 8 comments
Closed

High CPU usage when working with cgo #2598

RadhiFadlillah opened this issue Jun 25, 2019 · 8 comments

Comments

@RadhiFadlillah
Copy link

As title said, I'm experiencing high CPU usage when working with a cgo project. This problem happened everytime I type a character which can be seen here.

Here are my vscode-go settings :

"go.formatTool": "goimports",
"go.autocompleteUnimportedPackages": false,
"go.installDependenciesWhenBuilding": false,
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.buildOnSave": "off",
@ramya-rao-a
Copy link
Contributor

Thanks for reporting @RadhiFadlillah

@stamblerre Based on the settings shared above, the only tool that the Go extension calls on each letter being typed is your fork of gocode. Is it also responsible for the calls to gcc, go list etc?

@RadhiFadlillah Can you try the new language server feature we have? That will avoid calling gocode for completion feature.

@RadhiFadlillah
Copy link
Author

Hi @ramya-rao-a, thanks for the response.

Can you try the new language server feature we have? That will avoid calling gocode for completion feature.

Yes, I've already tried the language server. Unfortunately, it doesn't work any better, as can be seen here. After I enabled the language server and reload the window, the CPU usage started to spike even before I type anything. Soon after, gopls crashed.

... the only tool that the Go extension calls on each letter being typed is your fork of gocode. Is it also responsible for the calls to gcc, go list etc?

Yes, that's also my first thought, and I was planned to submit this issue in @stamblerre repository. However, when I checked the source code for gocode, I didn't see any call to go list -compiled=true command. Hence why I decided to post this issue here.

@RadhiFadlillah
Copy link
Author

After looking around, I found out that while gocode doesn't call go list by itself, it depends on golang.org/x/tools/go/packages which uses go list.

Since gocode uses go/packages with LoadSyntax mode, the go/packages end up using go list with -compiled flag set to true, which lead to high CPU usage in cgo project.

The same thing also happened with gopls, because it uses go/packages with NeedCompiledGoFiles mode, which lead to high CPU usage as well.

With that said, I guess the problem is not from vscode-go, gocode or gopls, but instead from go/packages.

@ramya-rao-a
Copy link
Contributor

Thanks for the follow up @RadhiFadlillah!

Can you log an issue with your findings at https://github.com/golang/go/ and provide a link here?

cc @stamblerre, @ianthehat

@stamblerre
Copy link
Contributor

@RadhiFadlillah are you using go1.12? There were some issues with cgo and go/packages that should have been improved in go1.12.

@RadhiFadlillah
Copy link
Author

@ramya-rao-a sorry for late response, I've opened it in go#32821.

@stamblerre I'm using Go 1.12.5. Both gocode and go/packages have been updated to latest commit as well.

@stamblerre
Copy link
Contributor

stamblerre commented Feb 11, 2020

@RadhiFadlillah: Is this still an issue for you? gopls should work better for cgo than gocode does, if you are interested in trying that out as an alternative.

@vscodebot
Copy link

vscodebot bot commented Feb 18, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. Thank you for your contributions.

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 3, 2020
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

3 participants