My zsh has been a little slow to start for a while. Never enough to be a significant bother, but always something I’ve been meaning to get around to. Thorsten Ball had a great writeup about this here. Maybe I’ve had weights in my shoes for too long!
Recently I’ve been messing with the atuin init
command - this is ran at shell startup. I want to ensure it’s fast, and we don’t cause slow shells for anyone.
What I did:
- Whack
zmodload zsh/zprof
at the top of my.zshrc
zprof
at the bottom of the same file
Upon opening a new shell, I get a nice table showing where zsh is spending time
It’s pretty obvious that nvm
is to blame here! With a bit of Googling, it seems like I’m among the last to figure this out. Oops.
Fixing it
I do use nvm reasonably often, so let’s fix it
Lazy loading
zsh-lazyload allows you to lazy load commands! That way I only pay the slow nvm penalty when I’m actually using nvm. Not bad.
Install the plugin as per the readme (I used zplug), and then
lazyload nvm -- 'source ~/.nvm/nvm.sh'
in my .zshrc. Good to go!
Replacements
There are a number of other options nowadays. I’ve been debating using asdf or mise, but haven’t gotten around to figuring out which works best for me.