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

Extension can't do IntelliSense, it blocks new procs, and it spikes CPU #3208

Closed
willfaught opened this issue Apr 26, 2020 · 7 comments
Closed

Comments

@willfaught
Copy link

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

  • Run go version to get version of Go
    • go version go1.14.2 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.44.2
      ff915844119ce9485abfe8aa9076ec76b5300ddd
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.14.1
  • Run go env GOOS GOARCH to get the operating system and processor architecture details
    • darwin
      amd64

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"] prefixes.

"go.addTags": {
		"tags": "json",
		"options": "json=omitempty",
		"promptForTags": false,
		"transform": "snakecase"
	},

	// Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools or versioned tools from https://gopkg.in.
	"go.alternateTools": {},

	// Include unimported packages in auto-complete suggestions.
	"go.autocompleteUnimportedPackages": false,

	// Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"])
	"go.buildFlags": [],

	// Compiles code on file save using 'go build -i' or 'go test -c -i'. Options are 'workspace', 'package', or 'off'.
	"go.buildOnSave": "package",

	// The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set.
	"go.buildTags": "",

	// This option lets you choose the way to display code coverage. Choose either to highlight the complete line or to show a decorator in the gutter. You can customize the color for the former and the style for the latter.
	"go.coverageDecorator": {
		"type": "highlight",
		"coveredHighlightColor": "rgba(64,128,128,0.5)",
		"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
		"coveredGutterStyle": "blockblue",
		"uncoveredGutterStyle": "slashyellow"
	},

	// Use these options to control whether only covered or only uncovered code or both should be highlighted after running test coverage
	"go.coverageOptions": "showBothCoveredAndUncoveredCode",

	// If true, runs 'go test -coverprofile' on save and shows test coverage.
	"go.coverOnSave": false,

	// If true, shows test coverage when Go: Test Function at cursor command is run.
	"go.coverOnSingleTest": false,

	// If true, shows test coverage when Go: Test Single File command is run.
	"go.coverOnSingleTestFile": false,

	// If true, shows test coverage when Go: Test Package command is run.
	"go.coverOnTestPackage": true,

	// Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.
	"go.delveConfig": {
		"dlvLoadConfig": {
			"followPointers": true,
			"maxVariableRecurse": 1,
			"maxStringLen": 64,
			"maxArrayValues": 64,
			"maxStructFields": -1
		},
		"apiVersion": 2,
		"showGlobalVariables": true
	},

	// Pick 'godoc' or 'gogetdoc' to get documentation. Not applicable when using the language server.
	"go.docsTool": "godoc",

	// Experimental Feature: Enable/Disable entries from the context menu in the editor.
	"go.editorContextMenuCommands": {
		"toggleTestFile": true,
		"addTags": true,
		"removeTags": false,
		"testAtCursor": true,
		"testFile": false,
		"testPackage": false,
		"generateTestForFunction": true,
		"generateTestForFile": false,
		"generateTestForPackage": false,
		"addImport": true,
		"testCoverage": true,
		"playground": true,
		"debugTestAtCursor": true
	},

	// Feature level setting to enable/disable code lens for references and run/debug tests
	"go.enableCodeLens": {
		"references": false,
		"runtest": true
	},

	// Flags to pass to format tool (e.g. ["-s"])
	"go.formatFlags": [],

	// Pick 'gofmt', 'goimports', 'goreturns' or 'goformat' to run on format. Not applicable when using the language server. Choosing 'goimports' or 'goreturns' will add missing imports and remove unused imports.
	"go.formatTool": "goreturns",

	// Additional command line flags to pass to `gotests` for generating tests.
	"go.generateTestsFlags": [],

	// Enable gocode's autobuild feature. Not applicable when using the language server.
	"go.gocodeAutoBuild": false,

	// Additional flags to pass to gocode. Not applicable when using the language server.
	"go.gocodeFlags": [
		"-builtin",
		"-ignore-case",
		"-unimported-packages"
	],

	// Used to determine the Go package lookup rules for completions by gocode. Only applies when using nsf/gocode. Latest versions of the Go extension uses mdempsky/gocode by default. Not applicable when using the language server.
	"go.gocodePackageLookupMode": "go",

	// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
	"go.gopath": null,

	// Specifies the GOROOT to use when no environment variable is set.
	"go.goroot": null,

	// Folder names (not paths) to ignore while using Go to Symbol in Workspace feature
	"go.gotoSymbol.ignoreFolders": [],

	// If false, the standard library located at $GOROOT will be excluded while using the Go to Symbol in File feature
	"go.gotoSymbol.includeGoroot": false,

	// If false, the import statements will be excluded while using the Go to Symbol in File feature
	"go.gotoSymbol.includeImports": false,

	// Infer GOPATH from the workspace root.
	"go.inferGopath": false,

	// If true, then `-i` flag will be passed to `go build` everytime the code is compiled.
	"go.installDependenciesWhenBuilding": true,

	// Use this setting to enable/disable experimental features from the language server.
	"go.languageServerExperimentalFeatures": {
		"format": true,
		"diagnostics": true,
		"documentLink": true
	},

	// Flags like -rpc.trace and -logfile to be used while running the language server.
	"go.languageServerFlags": [],

	// Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
	"go.lintFlags": [],

	// Lints code on file save using the configured Lint tool. Options are 'file', 'package', 'workspace' or 'off'.
	"go.lintOnSave": "package",

	// Specifies Lint tool name.
	"go.lintTool": "golint",

	// Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay.
	"go.liveErrors": {
		"enabled": false,
		"delay": 500
	},

	// 
	"go.playground": {
		"openbrowser": true,
		"share": true,
		"run": true
	},

	// Tags and options configured here will be used by the Remove Tags command to remove tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, all tags and options will be removed.
	"go.removeTags": {
		"tags": "",
		"options": "",
		"promptForTags": false
	},

	// Absolute path to a file containing environment variables definitions. File contents should be of the form key=value.
	"go.testEnvFile": null,

	// Environment variables that will passed to the process that runs the Go tests
	"go.testEnvVars": {},

	// Flags to pass to `go test`. If null, then buildFlags will be used.
	"go.testFlags": null,

	// Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled.
	"go.testOnSave": false,

	// The Go build tags to use for when running tests. If null, then buildTags will be used.
	"go.testTags": null,

	// Specifies the timeout for go test in ParseDuration format.
	"go.testTimeout": "30s",

	// Environment variables that will passed to the processes that run the Go tools (e.g. CGO_CFLAGS)
	"go.toolsEnvVars": {},

	// Location to install the Go tools that the extension depends on if you don't want them in your GOPATH.
	"go.toolsGopath": "",

	// Complete functions with their parameter signature, including the variable types
	"go.useCodeSnippetsOnFunctionSuggest": false,

	// Complete functions with their parameter signature, excluding the variable types
	"go.useCodeSnippetsOnFunctionSuggestWithoutType": false,

	// When enabled, the extension automatically checks the Go proxy if there are updates available for the Go tools (at present, only gopls) it depends on and prompts the user accordingly
	"go.useGoProxyToCheckForToolUpdates": true,

	// Use the Go language server "gopls" from Google for powering language features like code navigation, completion, formatting & diagnostics.
	"go.useLanguageServer": false,

	// Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"])
	"go.vetFlags": [],

	// Vets code on file save using 'go tool vet'. Options are 'workspace', 'package or 'off'.
	"go.vetOnSave": "package",

Describe the bug

On macOS, running the extension seems to prevent new processes from being created. When I try to open new terminals, I see:

[forkpty: Resource temporarily unavailable]
[Could not create a new process and open a pseudo-tty.]

and the "Code Helper (Renderer)" process CPU % spikes to 100%+ (usually 102-120%). Also, the Go extension stops being able to display info about Go types when you hover over them (it just says "Loading..."), and Cmd-clicking type identifiers doesn't work.

code --disable-extension ms-vscode.go fixes the terminal and CPU % problem, although obviously the IntelliSense features don't work for Go code too, as expected.

Steps to reproduce the behavior:

  1. Use the latest VS Code, Go extension, and Go on macOS Mojave (v10.14.6 [18G87]).
  2. Don't use gopls. (Not sure if this is related, but included for the sake of reproducibility.)
  3. Upgrade all the helper tools for Go. (Not sure if this is related, but included for the sake of reproducibility.)
  4. Open a Go file.
  5. Hover your mouse over some types to get the IntelliSense feature going.
@hyangah
Copy link
Contributor

hyangah commented Apr 27, 2020

@willfaught thanks for the report.

  • Were you still able to reproduce with the old version of the extension (v0.13.x)?
  • Do you have a cpu profile and process explorer output to share?

https://github.com/microsoft/vscode/wiki/Performance-Issues#visual-studio-code-is-consuming-a-lot-of-cpu

Thanks!

@willfaught
Copy link
Author

willfaught commented Apr 29, 2020

I don't know how to use an old version of an extension. Can you point me to a link?

When I look at Activity Monitor (macOS) while the problem happens, I see about 125 pgrep processes under a "Code Helper (Renderer)" process (which spiked up to 151% this time). There's also a godef process.

Note that since I can't create new processes, I can't run code --status:

$ code --status
Could not create child process - exiting
fork: Resource temporarily unavailable
<E> fish: Backtrace:
0   execute_fork() + 184
1   exec_process_in_job(parser_t&, process_t*, std::__1::shared_ptr<job_t> const&, io_chain_t const&, autoclose_pipes_t, fd_set_t const&, autoclose_pipes_t const&, unsigned long, bool) + 3061
2   exec_job(parser_t&, std::__1::shared_ptr<job_t> const&, job_lineage_t const&) + 977
3   parse_execution_context_t::run_1_job(tnode_t<grammar::job>, block_t const*) + 1231
4   parse_execution_context_t::run_job_conjunction(tnode_t<grammar::job_conjunction>, block_t const*) + 137
5   eval_result_t parse_execution_context_t::run_job_list<grammar::job_list>(tnode_t<grammar::job_list>, block_t const*) + 118
6   parse_execution_context_t::eval_node(tnode_t<grammar::job_list>, block_t const*) + 228
7   eval_result_t parser_t::eval_node<grammar::job_list>(std::__1::shared_ptr<parsed_source_t const> const&, tnode_t<grammar::job_list>, job_lineage_t, block_type_t) + 384
8   parser_t::eval(std::__1::shared_ptr<parsed_source_t const> const&, io_chain_t const&, block_type_t) + 223
9   parser_t::eval(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, io_chain_t const&, block_type_t) + 128
10  reader_run_command(parser_t&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) + 373
11  reader_read(parser_t&, int, io_chain_t const&) + 1009
12  main + 5650
13  start + 1

Here's what code --status says when the problem isn't happening, in case that helps:

2020-04-28 19:11:44.682 Code Helper (GPU)[23584:3374087] PLClientLogging: unknown permission type 2
Version:          Code 1.44.2 (ff915844119ce9485abfe8aa9076ec76b5300ddd, 2020-04-16T17:07:18.473Z)
OS Version:       Darwin x64 18.7.0
CPUs:             Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz (4 x 3800)
Memory (System):  16.00GB (0.03GB free)
Load (avg):       3, 2, 2
VM:               0%
Screen Reader:    no
Process Argv:     .
GPU Status:       2d_canvas:                     enabled
                  flash_3d:                      enabled
                  flash_stage3d:                 enabled
                  flash_stage3d_baseline:        enabled
                  gpu_compositing:               enabled
                  metal:                         disabled_off
                  multiple_raster_threads:       enabled_on
                  oop_rasterization:             disabled_off
                  protected_video_decode:        unavailable_off
                  rasterization:                 enabled
                  skia_renderer:                 disabled_off_ok
                  video_decode:                  enabled
                  viz_display_compositor:        enabled_on
                  viz_hit_test_surface_layer:    disabled_off_ok
                  webgl:                         enabled
                  webgl2:                        enabled

CPU %	Mem MB	   PID	Process
    1	    66	 20260	code main
    5	    33	 20267	   gpu-process
    0	    16	 20269	   utility
   12	   115	 20270	   window (syntax_conv_test.go — turbine)
    0	    33	 20275	     watcherService
    0	    33	 20281	     searchService
    0	    49	 20276	   shared-process
    0	     0	 23587	     /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=

Workspace Stats: 
|  Window (syntax_conv_test.go — turbine)
|    Folder (turbine): 43 files
|      File types: go(25) gitignore(1) yml(1) md(1) mod(1) sum(1)
|      Conf files:

Sometimes the pgrep processes disappear (and I can create processes again), but I can trigger them again reliably by (restarting Extension Host if necessary and then) hovering over Go type identifiers to trigger IntelliSense.

Sorry, no screenshots, since it seems to break the macOS screenshot keyboard shortcuts.

The Running Extensions window says the Go extension is "Unresponsive" and has a "Performance Issue", with a caution icon next to it.

Extension profile: extension-CPU-20200429T022132.615Z.cpuprofile.txt

Renderer profile: renderer-CPU-20200428T192654.cpuprofile.txt

Note that the "Extension Host" crashes occasionally and it gives me a button to restart it.

@hyangah
Copy link
Contributor

hyangah commented Apr 29, 2020

@willfaught thanks for capturing the profile data.
To use an old version of the extension, open the extensions view ( ⇧⌘X ) and then select the Go extension -> Install Another Version. Then choose any of 0.13.x.

image

Indeed it's showing it uses a lot of CPUs spawning (probably pgrep) to build a process tree. This is the same symptom as described in #3178 (comment) but you are not using golangci-lint.

Have you tried the language server (gopls) instead? It's still alpha so it may lack some features, but often it's better than depending on tens of independent tools. You can enable this by setting "go.useLanguageServer": true. https://cs.opensource.google/go/tools/+/master:gopls/doc/vscode.md is more detailed info about setting.

@willfaught
Copy link
Author

It repros on v14.0, but not v13.1.

I haven't tried gopls. I will eventually once it's stable and the community (and vscode-go) switches to it as the default.

@ramya-rao-a
Copy link
Contributor

@willfaught I went over the changelog for version 0.14.0, but couldnt find anything that would cause this. Please run the command Developer: Open Process Explorer to open the process explorer that can show which processes are causing the CPU spike.

@hyangah
Copy link
Contributor

hyangah commented Jun 3, 2020

@willfaught Noticed you were also on mac, and I wonder if you were also experiencing the same issue caused by golang/vscode-go#90 (comment).
Can you please check which pgrep command you are using?

@stamblerre
Copy link
Contributor

Given that we believe the issue can be fixed through a work-around (and will have a proper fix in the Go Nightly extension soon), I'm going to close this. @willfaught, please open a new issue in the https://github.com/golang/vscode-go repository if you are still encountering this.

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