Eryn Wells

Profiling ZSH

I’ve been hacking on my dotfiles a lot lately. One of the things that has bothered me about my shell setup is how long it takes zsh to start up. I did some research and found this blog post from someone who undertook the same project.

TIL, ZSH has a profiler built in. You can start it by calling the following.

zmodload zsh/zprof

Then, once you’re done, you call zprof to get a report that tells you where ZSH is spending most of its time. I put the line above at the top of my .zshenv and then called zprof at the end of my .zshrc.

Over the years, my shell init has grown organically in various ways as needs arise. I add things, hack around to make things work, and don’t generally pay attention to the overall structure of it. I’ve also frankly never spent a lot of time to learn the quirks of how ZSH behaves, and the most efficient ways of doing things. So, when I started this process, my init was taking close to a second. By the end, it was down to about 100 ms. Not bad for a couple hours of work. :)