Skip to content

Instantly share code, notes, and snippets.

@ctechols
Last active April 3, 2025 17:32
Show Gist options
  • Save ctechols/ca1035271ad134841284 to your computer and use it in GitHub Desktop.
Save ctechols/ca1035271ad134841284 to your computer and use it in GitHub Desktop.
Speed up zsh compinit by only checking cache once a day.
# 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;
@joshuataylor
Copy link

joshuataylor commented Jan 31, 2025

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.

@pa-0
Copy link

pa-0 commented Feb 3, 2025

Does anybody have a .zcompdump_capture file being created in their $HOME directory?

@quyenvsp
Copy link

@forivall hello, did you created MR?

@FlorianHeigl
Copy link

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)

@forivall
Copy link

forivall commented Apr 3, 2025

@quyenvsp not yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment