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

High CPU during go vet #1215

Closed
codingconcepts opened this issue Sep 15, 2017 · 24 comments
Closed

High CPU during go vet #1215

codingconcepts opened this issue Sep 15, 2017 · 24 comments

Comments

@codingconcepts
Copy link

Hi team,

Not sure if this is related to #1035 but whenever I save and go vet kicks in, my CPU seems to indefinitely spin at ~45% CPU for each instance of vet.exe. When I say each instance, there's a new instance of vet.exe spun up per save as well (until my PC grinds to a halt that is).

Any ideas on why this might be? It doesn't seem to be affected by the source it's trying to process either, I'm able to reproduce with a simple hello world program!

Here's some info for you:

Basics:

OS: Windows 10
Go version: go1.8 windows/amd64
Version: 1.16.1
Commit: 2749...
Shell: 1.7.3
Renderer: 58.0.3029.110
Node: 7.9.0
Arch: ia32

Settings:

{
  "editor.fontSize": 16,
  "editor.wordWrap": "on",
  "editor.renderIndentGuides":false,

  "files.autoSave": "onFocusChange",
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/.DS_Store": true,
    "**/*.exe": true,
    "**/*.out": true
  },

  
  "go.coverOnSave": false,
  "go.formatTool": "goimports",

  "window.zoomLevel": 0,
  "workbench.iconTheme": "vs-seti",
  "workbench.colorTheme": "An Old Hope Light",
  "workbench.startupEditor": "newUntitledFile"
}

Extensions:

Go: 0.6.65

Please let me know if there's anything else I can provide to help diagnose.

Cheers,

Rob

@ramya-rao-a
Copy link
Contributor

Well... I don't have a clue here especially because you also mention that you can repro this with a simple hello world program!

You have autosave enabled, so that would trigger vet for every save.
go tool vet is run to vet the code. I am not sure if vet.exe is run internally or you have some other extension installed. Do you have any other Go related extensions installed?

Until the problem is fixed, you can set go.vetOnSave to false to unblock yourself

@cmaglie
Copy link

cmaglie commented Oct 25, 2017

I have the same issue, it seems that vet runs for a very long time and keeps a cpu core at 100% (it takes almost a minute to complete on my machine).

image

I've run a strace over the vet process and it seems that it "rescan" all the files in GOPATH I don't know if this is the intended behaviour, below there is an extract:

$ sudo strace -fp 22497 -e openat
strace: Process 22497 attached with 9 threads
strace: [ Process PID=22503 runs in x32 mode. ]
strace: [ Process PID=22503 runs in 64 bit mode. ]
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/all-core/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22502] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22502] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v2.1/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.1/gles2", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/gos/go1.8.1/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/Workspace/go/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22499] openat(AT_FDCWD, "/home/megabug/.gvm/pkgsets/go1.8.1/global/pkg/linux_amd64/C.a", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-compatibility/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/conversions.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/debug.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/package.go", O_RDONLY|O_CLOEXEC) = 3
[pid 22503] openat(AT_FDCWD, "src/github.com/go-gl/gl/v3.2-core/gl/procaddr.go", O_RDONLY|O_CLOEXEC) = 3

@cmaglie
Copy link

cmaglie commented Oct 25, 2017

Ok, I guess I found the cause of this: I had a tab opened with a main.go in my GOPATH, when I closed that tab the vet command started to perform good again.

I think that vet examines all subfolders of all files opened in the editor, so having the $GOPATH/main.go opened has made it scan all the $GOPATH/src/... folder that was very crowded.

@dahankzter
Copy link

It seems that vet also scans the vendor tree and I have a pretty large vendor which makes it very sluggish.

When I save I see several vet . processes and the cpu goes skyhigh and it takes a long time to run even standalone.

/usr/lib/go/pkg/tool/linux_amd64/vet . 13.14s user 0.30s system 162% cpu 8.296 total

Shouldn't it just run vet *.go or some other heuristically picked file set?

@dahankzter
Copy link

Perhaps go vet . should be used instead? I am not perfectly clear why it differs to be honest but this form is very fast and does seem to ignore vendor.

@ramya-rao-a
Copy link
Contributor

@dahankzter Have you set go.vetOnSave to package or workspace ?

The only reason we use go tool vet . instead of go vet . is to give the user the option to use the settings go.vetFlags.

When you say that go vet . is faster, are you saying so when comparing with go tool vet . ?

@dahankzter
Copy link

dahankzter commented Nov 9, 2017

Yes go vet . is instantaneous while go tool vet . clearly scans my vendor folder and takes +10 seconds on my relatively fast laptop.

I have not set any specific config other than default and I really want as much as I can get on save but it needs to be fast enough for it to not lag.

@ramya-rao-a
Copy link
Contributor

How does go vet ./... fare?

@dahankzter
Copy link

It is also fast.

@ramya-rao-a
Copy link
Contributor

@dahankzter Thanks

I have made a few tweaks

  • Use go vet ./... instead of go tool vet . when there are no flags to be passed i.e go.vetFlags is an empty array
  • Added the command Go: Vet Current Package and Go: Vet Workspace to allow the option to vet on demand instead of relying on vet on save feature which can get expensive on larger projects
  • Kill existing processes spawned for vetting when a new request for vetting is made either via the new commands or the vet on save feature

I'll release an update next week, until then can you try out the changes and give feedback? All you have to do is:

@dahankzter
Copy link

dahankzter commented Nov 13, 2017 via email

@dahankzter
Copy link

dahankzter commented Nov 13, 2017

I see no lagging at all with the latest extension! Thanks for this!

@ramya-rao-a
Copy link
Contributor

The perf improvements mentioned in #1215 (comment) are now out in the latest update to the Go extension (0.6.69)

@dahankzter
Copy link

Cool, when is this published? I seem to be still on 0.6.67

@dahankzter
Copy link

Somehow reinstalling the plugin worked but the "update available" had not s tarted to show. Could it be because I installed it manually?

@ramya-rao-a
Copy link
Contributor

That shouldn't be the case. For now, uninstall and install it again, you should get the latest.
I'll look into if there are any issues with extension update when installed manually using vsix

@dahankzter
Copy link

That seems to have worked,thx!

@jnewmoyer
Copy link

From what I can tell, "go tool vet ." and "go vet ./..." should actually behave the same, recursively process all packages at or below the current directory. I installed the update and performance is definitely better, I just can't tell why. If I run those two commands from the terminal they both do the same thing, and take the same amount of time to complete. But with the extension on save, it goes by really quick. I feel like something else is going on there.

@dahankzter
Copy link

Packages yes but not vendor right?

@jnewmoyer
Copy link

In this case I have no vendor source. According to the go docs vendor source is skipped when using ... wildcards.

@dahankzter
Copy link

I have read back and forth before but it was a super clear difference now.

@ramya-rao-a
Copy link
Contributor

@jnewmoyer ./... does skip vendor directories. go vet ./... is valid way to use vet, go tool vet ./... is not. Try it.

@jnewmoyer
Copy link

The alternative was go tool vet . was it not?

@ramya-rao-a
Copy link
Contributor

Yes, but go tool vet . does not exclude vendor directories

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

No branches or pull requests

5 participants