zinit: [bug]: Constant CPU usage
What happened?
Hello, I noticed with even just a plain zinit .zshrc, around 0.7% per shell is used; this increases with more plugins.
Steps to reproduce
.zshrc
with contents:
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
source "${ZINIT_HOME}/zinit.zsh"
Relevant output
No response
Screenshots and recordings
Zinit with no plugins:
Zinit with plugins:
zsh -df
:
Operating System & Version
OS: linux-gnu | Vendor: unknown | Machine: x86_64 | CPU: x86_64 | Processor: unknown | Hardware: x86_64
Zsh version
zsh 5.9 (x86_64-unknown-linux-gnu)
Terminal emulator
alacritty
If using WSL on Windows, which version of WSL
No response
Additional context
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19 (12 by maintainers)
@reportaman Noted. Thanks for the information!
I’ve finally got some time to dig into this tonight and over Labor day weekend.
To answer your questions:
I started a new Zsh instance with debugging via:
and saw this output over and over when idle.
There is another tool I like for debugging, but will be cumbersome/frustrating to use if you aren’t super familiar with using a debugger. That said, observability is useful even if you’re just debugging your personal ZSH configuration.
https://zshdb.readthedocs.io/en/latest/
I’ve hunted down this code that I will investigate.
It seems to be constantly running in the background
I can reproduce this on Linux with the current main branch at 68a6b42caf224b2ca2c172d58daf9faf5c86beb9. The culprit is the chpwd hook set for
@zinit-scheduler
, which ends up adding a new sched chain every time the directory is changed (this was added in e28cab88c94232350d46bc1d6b52cd43830e24b6):https://github.com/zdharma-continuum/zinit/blob/68a6b42caf224b2ca2c172d58daf9faf5c86beb9/zinit.zsh#L2486-L2498
I think a general fix would be to only add a sched entry if there’s not already one present in
$zsh_scheduled_events
(both here and at the top of the function). I’m not sure how the bug referenced on line 2495 would interact with that, though.As a side note, I used
perf stat -I 1000 --interval-clear -p <zsh pid>
to look at detailed CPU usage on Linux, and got similar results to @poetaman.