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

CPU overuse due to go doc processes #2276

Closed
jpincas opened this issue Jan 27, 2019 · 24 comments
Closed

CPU overuse due to go doc processes #2276

jpincas opened this issue Jan 27, 2019 · 24 comments

Comments

@jpincas
Copy link

jpincas commented Jan 27, 2019

I know this has been logged in multiple issues before, but they are all closed as far as I can see. Common to those reports, the extension is driving the CPUs in my MacBook Pro through the roof, causing it to overheat and the fans to spin like crazy.

  • I have installed, reinstalled and clean reinstalled both VsCode and the extension 3-4 times.
  • I normally get about 15 minutes of normal use before this behaviour starts.
  • Only get this when coding Go.
  • Have updated Go tools with Go : Update / Reinstall tools
  • Have added both "go.docsTool": "gogetdoc" and "go.useLanguageServer": true to my settings and reloaded, as suggested in other threads.

I attach a screenshot of the process viewer mid-spike, that pretty clearly shows that its the doc process causing the problem.

screenshot 2019-01-26 at 23 39 39

Please help if you can - I code Go all day every day and this is making my life really, really hard right now. Sometimes the spikes cause the cursor to skip to another pane, and when I look up, I've written code in the middle of another file!

@tj
Copy link

tj commented Jan 28, 2019

I get this all the time as well, I tried updating all the Go tools using the install/update command but no luck (Sierra), you pretty much can't type without it spawning dozens of these

@jpincas
Copy link
Author

jpincas commented Jan 28, 2019

Good to know someone else has experienced it - it's really making work hard. As you start typing, you can see the linting and suggestions start to slow down to a crawl until they end up not working at all until the CPU has recovered!!

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 29, 2019

Thanks for reporting @jpincas

This is most likely due to the auto-completion widget now showing docs for which the go doc processes are being spawned.

Install our latest beta version of this extension to be able to disable the docs feature and see if that helps.

Add the below in your settings after installing the beta version

"go.gocodeFlags": [
		"-builtin",
		"-ignore-case",
		"-unimported-packages",
		"-exclude-docs"
	]

The first 3 are default flags we send to gocode. The 4th will disable the docs feature in auto-completion widget

@ramya-rao-a ramya-rao-a changed the title CPU overuse CPU overuse due to go doc processes Jan 29, 2019
@jpincas
Copy link
Author

jpincas commented Jan 29, 2019

Thanks Ramya - have installed the beta version and added those settings. Will report back after a days work.

@jpincas
Copy link
Author

jpincas commented Jan 29, 2019

OK, I can already report that it is constantly asking me install the latest version of gocode, even though I have done so twice.

@tj
Copy link

tj commented Jan 29, 2019

Should these processes have some kind of timeout? In my case it often (always?) shows undefined as well, as seen in #2248, maybe a bug? I've been working in Go WASM lately, maybe that's part of the problem, I forget now if I had this issue with non-js,wasm build tags

I tried updating to the beta as well, still get dozens when typing as normal.

tj               24422  76.6  0.1  2543312  23436   ??  U    12:33pm   0:16.35 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined createApp
tj               24444  64.7  0.1  2541264  16880   ??  R    12:33pm   0:07.27 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined createApp
tj               24470  64.2  0.1  2542352  16680   ??  U    12:33pm   0:04.59 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined app
tj               24433  63.5  0.1  2541520  23236   ??  R    12:33pm   0:14.31 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined createApp
tj               24478  62.8  0.1  2541008  17084   ??  U    12:33pm   0:04.53 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined newApp
tj               24427  62.2  0.1  2542544  23276   ??  R    12:33pm   0:16.09 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined createApp
tj               24465  61.9  0.1  2541264  16968   ??  R    12:33pm   0:04.73 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined app
tj               24483  60.4  0.1  2541520  17036   ??  R    12:33pm   0:04.28 /usr/local/go/pkg/tool/darwin_amd64/doc -c -cmd -u undefined newApp

@jpincas
Copy link
Author

jpincas commented Jan 29, 2019

@tj Did you also add the "--exclude-docs" option to your config as suggested by @ramya-rao-a above? That seems to solve it, but of course it disables the intelligent autocomplete, which makes writing code suck!!

@ramya-rao-a Is there any timeline for a proper fix on this?

@ramya-rao-a
Copy link
Contributor

@jpincas The flag is -exclude-docs not --exclude-docs, I have corrected it in my comment above. Once you make that change, you shouldn't see any more prompts for gocode.
Regardless, I'll make that part of the code more resilient

@tj Thats a good idea about the timeout, I'll look into it.

@tj
Copy link

tj commented Jan 31, 2019

strange, -exclude-docs fixed it until I restarted my machine, now it's back to spawning them, the user setting is still set correctly. I tried re-installing the beta as well.

@ramya-rao-a
Copy link
Contributor

@tj are you sure your user setting is not getting overriden by workspace settings?

@ramya-rao-a
Copy link
Contributor

If not then close any running gocode process and then try again in VS Code

@tj
Copy link

tj commented Feb 1, 2019

double checked the workspace settings but mine are empty, I tried gocode exit and restarting vscode a few times but somehow it's still doing it. Thanks for the help by the way :D vscode seems much nicer than Atom so far

@tj
Copy link

tj commented Feb 1, 2019

I ran find . -name "node_modules" -exec rm -rf '{}' + (WARNING: dont blame me for losing stuff haha) to remove node modules recursively, since many repos in my GOPATH also have Node-based client code, now unsuccessful go doc lookups are quite a bit faster:

$ time go doc something

real	2m25.068s
user	0m17.772s
sys	1m45.039s

$ time go doc something

real	0m19.955s
user	0m2.499s
sys	0m9.343s

It might be safe to close this issue since go doc is at fault for the CPU usage. My thoughts so far for improvements would maybe be:

  • add a timeout for maybe a few seconds, since showing the docs after a huge delay isn't super useful anyway
  • kill previous go doc processes when spawning a new one as the old results are no longer going to be displayed

@ramya-rao-a
Copy link
Contributor

That is a little weird @tj... Why would node_modules have any affect on go doc?

We do have a cancellation token in place for the auto-completion feature. When a previous request is no longer valid (say because you continued typing and now are on a different word), then cancellation token for the previous request is cancelled by VS Code.

And we do listen to this cancellation and kill the go doc process. Looks like this token is not getting cancelled properly, thats the only explanation I can come up with for why these processes are lingering.

@tj
Copy link

tj commented Feb 1, 2019

I think go doc is just traversing too many directories searching for a match. I opened an issue for that here, Brad seemed open to black-listing node_modules: golang/go#30058

@jpincas
Copy link
Author

jpincas commented Feb 4, 2019

Sorry for the dumb question - but when we talk about 'showing the docs', are we talking about the intelligent completion suggestions, or something else?

@ramya-rao-a
Copy link
Contributor

Not a dumb question at all @jpincas

Generally, "showing the docs" could either refer to the docs that accompany the suggestion widget or what you see when you hover over symbols.

But in this case, we are referring to the former.

@snikch
Copy link

snikch commented Feb 11, 2019

I've been battling this same problem for the last 6 months or so.

@ramya-rao-a I can confirm excluding docs has worked for me, although there's the obvious drawbacks.

The node modules things has affected a whole lot of Go tools over the years. I even complained about it in 2016 for goimports https://twitter.com/snikchnz/status/749895907777269760

It would be great to have the tools ignoring node_modules but in the meantime skipping the doc generation will have to do 👍. Thanks for looking into it.

@jpincas
Copy link
Author

jpincas commented Feb 17, 2019

The -exclude-docs tag is no longer having any effect for me. The docs are showing and the CPU is on fire. I'm on version 0.9.2 - does that version recognise that tag? I thought I read on the Beta download page that auto-updating is disabled once you're on the Beta - so I'm not actually sure how I ended up on 0.9.2.

@jpincas
Copy link
Author

jpincas commented Feb 17, 2019

Even whilst doing nothing, go-langserver is eating my CPU.
screenshot 2019-02-17 at 10 01 47

@ramya-rao-a
Copy link
Contributor

@jpincas

Auto-updating doesn't get disabled once you are on beta. That only happens if you opt out using the setting extension.autoUpdate

No, there were no changes in 0.9.2 regarding the -exclude-docs

From your screenshot it looks like the language server is taking up the CPU and not the go doc process anymore. Using the -exclude-docs flag only helps with he problem caused by go doc

Regarding the problem with the language server, I would suggest to disable that. In a few weeks the team at Google will be ready with a their official language server which should perform better

@freman
Copy link
Contributor

freman commented Oct 23, 2019

Similar to the above, I'm on the latest beta (I think) 0.11.8-beta.2 and -exclude-docs seems not to be stopping the running of docs

image

my config looks like this

    "go.formatTool": "goimports",
    "go.testFlags": ["-v"],
    "go.gocodeFlags": [
		"-builtin",
		"-ignore-case",
		"-unimported-packages",
		"-exclude-docs"
	]

image

@stamblerre
Copy link
Contributor

An alternative to this work-around is to use the gopls language server, which handles cancellation.

I have also filed #3044 to track supporting correct cancellation for all subprocesses, so let's continue the discussion there. The correct fix would really be to limit the number of go doc processes that VS Code Go can start. I will close this issue in favor of #3044.

@stamblerre
Copy link
Contributor

Duplicate of #3044

@stamblerre stamblerre marked this as a duplicate of #3044 Feb 12, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 28, 2020
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

6 participants