Last active
April 3, 2025 17:32
-
Star
(185)
You must be signed in to star a gist -
Fork
(12)
You must be signed in to fork a gist
-
-
Save ctechols/ca1035271ad134841284 to your computer and use it in GitHub Desktop.
Speed up zsh compinit by only checking cache once a day.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On slow systems, checking the cached .zcompdump file to see if it must be | |
# regenerated adds a noticable delay to zsh startup. This little hack restricts | |
# it to once a day. It should be pasted into your own completion file. | |
# | |
# The globbing is a little complicated here: | |
# - '#q' is an explicit glob qualifier that makes globbing work within zsh's [[ ]] construct. | |
# - 'N' makes the glob pattern evaluate to nothing when it doesn't match (rather than throw a globbing error) | |
# - '.' matches "regular files" | |
# - 'mh+24' matches files (or directories or whatever) that are older than 24 hours. | |
autoload -Uz compinit | |
if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then | |
compinit; | |
else | |
compinit -C; | |
fi; | |
If you see random zsh CPU issues with subshells and compinit/background compilation, as certain IDEs like JetBrains (intellij, pycharm), vscode etc all will call this, and I've had instances where zsh got stuck doing funky things, causing CPU usage to max out.
I end up double checking interactive, login (which vscode/intellij both say they are), but also $INTELLIJ_ENVIRONMENT_READER and $TERM_PROGRAM.
Does anybody have a .zcompdump_capture
file being created in their $HOME
directory?
@forivall hello, did you created MR?
This has helped a bit with the start on OSX after they defaulted to zsh. (gonna set my user to go back to ksh93 anyway)
@quyenvsp not yet.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For oh-my-zsh users, I wrote a bit to integrate this check into oh-my-zsh. At some point, I'll submit a PR to omz: ohmyzsh/ohmyzsh@master...forivall:oh-my-zsh:use-cached-compdump
From my ad-hoc testing, this saves about 50ms on startup, on my dotfiles setup, which loads omz through
zgenom