Constant high CPU usage
Issue Prelude
Please complete these steps and check these boxes (by putting an x inside
the brackets) before filing your issue:
- [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [x] I have read and understood YCM's [README][readme], especially the [Frequently Asked Questions][faq] section.
- [x] I have searched YCM's issue tracker to find issues similar to the one I'm about to report and couldn't find an answer to my problem. ([Example Google search.][search])
- [x] If filing a bug report, I have included the output of
vim --version. - [x] If filing a bug report, I have included the output of
:YcmDebugInfo. - [x] If filing a bug report, I have attached the contents of the logfiles using
the
:YcmToggleLogscommand. - [x] If filing a bug report, I have included which OS (including specific OS version) I am using.
- [x] If filing a bug report, I have included a minimal test case that reproduces
my issue, using
vim -Nu /path/to/YCM/vimrc_ycm_minimal, including what I expected to happen and what actually happened. - [ ] If filing a installation failure report, I have included the entire output
of
install.py(orcmake/make/ninja) including its invocation - [x] I understand this is an open-source project staffed by volunteers and that any help I receive is a selfless, heartfelt gift of their free time. I know I am not entitled to anything and will be polite and courteous.
- [x] I understand my issue may be closed if it becomes obvious I didn't actually perform all of these steps.
Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.
Issue Details
Provide a clear description of the problem, including the following key questions:
On M1 Macbook Air, the Terminal app, not the vim process, has constant high CPU usage for each opened C++ file, including new files that don't exist.
With 3 new empty C++ files opened, the Terminal app takes 30+% CPU usage constantly, even when there's no input/action to vim. Currently I only found this problem with C++ files and with YCM enabled. The problem disappears if no C++ file is opened(e.g. only .py files) with YCM enabled, or C++ files are opened with disabled YCM, both takes 0.0% CPU usage.
With actual C++ files with complicated source code opened, even higher CPU usage is taken for each file and heats the computer constantly.
- What did you do?
Include steps to reproduce here.
vim -Nu vimrc_ycm_minimal test1.cpp test2.cpp test3.cpp -O, no.cppfiles have to exist.- Check CPU usage , no editing is needed.
If you made changes to
vimrc_ycm_minimal, pase them here:
No change is made.
-
What did you expect to happen? Don't take high CPU usage when idle.
-
What actually happened? Terminal app takes high CPU usage constantly.
Diagnostic data
Output of vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jun 18 2024 19:01:23)
macOS version - arm64
Included patches: 1-500
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm -tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
-balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
-browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl +title
+channel +ipv6 +persistent_undo -toolbar
+cindent +job +popupwin +user_commands
-clientserver +jumplist +postscript +vartabs
+clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3 +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby +wildignore
+cursorbind +lua +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con +mksession +smartindent +writebackup
+diff +modify_fname +sodium -X11
+digraphs +mouse +sound -xattr
-dnd -mouseshape +spell -xfontset
-ebcdic +mouse_dec +startuptime -xim
+emacs_tags -mouse_gpm +statusline -xpm
+eval -mouse_jsbterm -sun_workshop -xsmp
+ex_extra +mouse_netterm +syntax -xterm_clipboard
+extra_search +mouse_sgr +tag_binary -xterm_save
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
3rd user vimrc file: "~/.config/vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/opt/homebrew/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -o vim -lm -lncurses -lsodium -liconv -lintl -framework AppKit -L/opt/homebrew/opt/lua/lib -llua5.4 -mmacosx-version-min=14.2 -fstack-protector-strong -L/opt/homebrew/opt/perl/lib/perl5/5.38/darwin-thread-multi-2level/CORE -lperl -L/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -framework CoreFoundation -lruby.3.3 -L/opt/homebrew/Cellar/ruby/3.3.3/lib
Output of YcmDebugInfo
Printing YouCompleteMe debug information...
-- Resolve completions: Up front
-- Client logfile: /var/folders/kz/4wgytmy56ks64tslrymmc0vw0000gn/T/ycm_86u_2o90.log
-- Server Python interpreter: /opt/homebrew/opt/[email protected]/bin/python3.12
-- Server Python version: 3.12.4
-- Server has Clang support compiled in: False
-- Clang version: None
-- No extra configuration file found
-- C-family completer debug information:
-- Clangd running
-- Clangd process ID: 32966
-- Clangd executable: ['/Users/namniav/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/clangd/output/bin/clangd', '-header-insertion-decorators=0', '-resource-dir=/Users/namniav/.vim/plugged/Y
ouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/17.0.1', '-limit-results=500', '-log=verbose']
-- Clangd logfiles:
-- /var/folders/kz/4wgytmy56ks64tslrymmc0vw0000gn/T/clangd_stderr_3cfrw33.log
-- Clangd Server State: Initialized
-- Clangd Project Directory: /Users/namniav/.vim/plugged/YouCompleteMe
-- Clangd Open Workspaces: {'/Users/namniav/.vim/plugged/YouCompleteMe'}
-- Clangd Settings: {}
-- Clangd Compilation Command: False
-- Server running at: http://127.0.0.1:62916
-- Server process ID: 32964
-- Server logfiles:
-- /var/folders/kz/4wgytmy56ks64tslrymmc0vw0000gn/T/ycmd_62916_stdout_33v86uc8.log
-- /var/folders/kz/4wgytmy56ks64tslrymmc0vw0000gn/T/ycmd_62916_stderr_jrmf0b2z.log
-- Semantic highlighting supported: True
-- Virtual text supported: True
-- Popup windows supported: True
Output of YcmDiags
No warnings or errors detected.
Output of git rev-parse HEAD in YouCompleteMe installation directory
b5fe27bb82cc375d66a9a006cf30390bdb215ed2
Contents of YCM, ycmd and completion engine logfiles
Reproduce the issue with
vim -Nu /path/to/YCM/vimrc_ycm_minimal, which enabled debug logging and other useful diagnostics. Include a link to a [gist][] containing all of the log files listed by:YcmToggleLogs. clangd_stderr_3cfrw33.log ycm_86u_2o90.log ycmd_62916_stderr_jrmf0b2z.log ycmd_62916_stdout_33v86uc8.log
OS version, distribution, etc.
M1 Macbook Air, macOS 14.1 (23B74)
I can't reproduce.
From the logs I can see that YCM is making the expected (small) number of server message polls
YCM has a few timers that fire every ~100ms in normal mode and ~10ms in insert mode, but these callbacks are very light.
Do we know it's vim/ycmd? Considering clangd in the debug info, I bet this is just clangd indexing a big repo which is resuling in a long high cpu load.
For LLVM I needed a few hours for clangd to index everything. After that, it was smooth sailing.
@puremourning Thank you for investigating the issue.
Did you start vim with -O option to open windows side by side for each file? I noticed that more vim windows(splits) for C++ files, higher constant cpu usage taken by Terminal. Without -O it's about 14% on my side.
I can reproduce the issue stably, is there something else I could try and provide?
Do we know it's vim/ycmd? Considering clangd in the debug info, I bet this is just clangd indexing a big repo which is resuling in a long high cpu load.
No, it's not vim/ycmd/clangd process, but only Terminal taking constant high cpu usage. It's reproducible in any empty directory on my side.
I just restarted macOS and it's lower but still unexpectedly high. It's about 19% with -O and 7.x% without -O.
In directory /tmp:
-
YCM + CPP +
-O:vim -Nu ~/.vim/plugged/YouCompleteMe/vimrc_ycm_minimal test1.cpp test2.cpp test3.cpp -O -
YCM + CPP:
vim -Nu ~/.vim/plugged/YouCompleteMe/vimrc_ycm_minimal test1.cpp test2.cpp test3.cpp -
YCM + PY +
-O:vim -Nu ~/.vim/plugged/YouCompleteMe/vimrc_ycm_minimal test1.py test2.py test3.py -O -
noYCM + CPP +
-O:vim -Nu NONE test1.cpp test2.cpp test3.cpp -O
Edit: The columns of ActivityMonitor are same as your screenshot above: Process Name | %CPU | CPU Time | Threads | Idle Wake-Ups | Kind | %GPU