Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% CPU usage and freeze in project with thousands of files #6000

Closed
Jeiwan opened this issue Jan 14, 2022 · 5 comments
Closed

100% CPU usage and freeze in project with thousands of files #6000

Jeiwan opened this issue Jan 14, 2022 · 5 comments
Labels
invalid Unactionable, unrelated, inappropriate, or a pilot error

Comments

@Jeiwan
Copy link

Jeiwan commented Jan 14, 2022

What did you expect to happen?

Doom Emacs doesn't freeze when working with Golang.

What actually happened?

When I open a Golang project, Doom Emacs freezes consuming 100% of CPU. I don't need to do anything, just open a Golang file. This lasts very long so I eventually had to kill it because it's unusable.
This whole project was programmed in Doom Emacs and everything had been ok until I updated Doom and Emacs a couple of days ago (I had an old version of Doom, maybe more than 6 months old).

This is a fresh install: Emacs 27.2, latest Doom. The only changes in init.el are uncommented go and lsp modules. There are no logs or error messages.

Describe your attempts to resolve the issue

It looks like it's indexing my project and its dependencies for autocompletion (I guess). The fact that it's Emacs that uses 100% CPU, not gopls, makes me think that.

The issue doesn't happen when go and lsp packages are not installed.

Steps to reproduce

  1. brew install --cask emacs
  2. git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
  3. ~/.emacs.d/bin/doom install
  4. Open Emacs, edit init.el, uncomment go and lsp modules.
  5. Run ~/.emacs.d/bin/doom sync and doom/reload.
  6. Open a big Golang project or a project that uses a heavy dependency.

System Information

https://pastebin.com/rimY6Bre

@Jeiwan Jeiwan added is:bug Something isn't working as intended needs-triage Issue hasn't been assessed yet labels Jan 14, 2022
@Jeiwan
Copy link
Author

Jeiwan commented Jan 14, 2022

I debugged it a little bit more:

  1. I left it running for several hours and it hadn't unfrozen.
  2. The issue happens only when go-mode is installed with LSP support.
  3. The issue happens only in one project. Other projects are ok.
  4. It starts hanging a few seconds after LSP is initialized (a message is printed).
  5. Reverting either lsp or go modes to older commits didn't help.
  6. This doesn't happen in VSCode, even though it also uses LSP.

@Jeiwan
Copy link
Author

Jeiwan commented Jan 14, 2022

Added this to config.el:

(setq lsp-go-gopls-server-args '("-logfile" "/Users/jeiwan/.tmp/gopls.log" "-vv" "-debug" ":8080"))

The log file is empty and there's nothing interesting on the debug server.

@Jeiwan Jeiwan changed the title 100% CPU usage and freeze in Golang project 100% CPU usage and freeze in project with thousands of files Jan 15, 2022
@Jeiwan
Copy link
Author

Jeiwan commented Jan 15, 2022

Alright, I found the cause. That project has 170+ thousand files (not related to Go). When Emacs opens it, it starts analyzing them or maybe caching or maybe indexing – and this is when it hangs.

I installed Doom at commit 42d5da8. When I opened the project, it showed me this message:

There are 173301 files in folder ... so watching the repo may slow Emacs down. Do you want to watch all files in ... ? (y or n)

When choosing n it works without issues, when choosing y it hangs.

At commit 79c1fce, everything works without any issues and it doesn't ask about watching files.

It seems that a module was added that scans/analyzes/watches all files in a project and it just cannot handle so many files. If so, the question is: how to ignore those files? (They're ignored in .gitignore)

@jeetelongname
Copy link
Member

What is the value of lsp-enable-file-watchers? back when I used to write go thats what caused the issue and it should be set to nil if not then you can set it to nil in go mode with this snippet

(setq-hook! 'go-mode-hook
     lsp-enable-file-watchers nil)

@Jeiwan
Copy link
Author

Jeiwan commented Jan 16, 2022

@jeetelongname Thanks for pointing this out! However, I do need the watchers, so I simply added the cache folder to ignored ones:

(with-eval-after-load 'lsp-mode
  (add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]cache\\'"))

@Jeiwan Jeiwan closed this as completed Jan 16, 2022
@hlissner hlissner added delete me invalid Unactionable, unrelated, inappropriate, or a pilot error and removed is:bug Something isn't working as intended needs-triage Issue hasn't been assessed yet labels Jan 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid Unactionable, unrelated, inappropriate, or a pilot error
Projects
None yet
Development

No branches or pull requests

3 participants