It seems like my shell is taking way too long to start up. Is there any way to profile it so I can figure out what\'s slowing it down so much?
You can start your timer at the first suspicious point in your ~/.zshrc
(or at the beginning):
integer t0=$(date '+%s') # move this around
... maybe something suspect ...
# End of zshrc
function {
local -i t1 startup
t1=$(date '+%s')
startup=$(( t1 - t0 ))
[[ $startup -gt 1 ]] && print "Hmm, poor shell startup time: $startup"
}
unset t0
This alerts me if ever I see a too-slow startup, and I leave it in as a permanent wrapper.
For more sophisticated measurements, there is a zsh module called zprof
. It's as simple as temporarily wrapping the contents of your ~/.zshrc
in a zmodload zsh/zprof
and zprof
. This will dump some verbose profiling tables that are easy enough to interpret.
More info in zshmodules(1)
manpage.
When I find things that are particularly slow (rbenv init, vcs_info check-for-changes, antigen, nvm, zsh-mime-setup, interpreter version checking, etc) I add SLOW
comments as reminders, and try to find workarounds. Slow startups can cause a lot grief, so I tend to avoid zsh packages/framewords whose inner workings I don't grok. compinit is the slowest thing I'm willing to live with and is ~half of total startup time.