--- title: "Profiling ZSH" date: 2022-01-23T11:35:38-08:00 description: In which I learn about how to profile my ZSH init files. draft: false categories: ["Tech"] tags: ["ZSH", "Dotfiles"] --- I've been hacking on my [dotfiles][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][debug-zsh] from someone who undertook the same project. TIL, ZSH has a profiler built in. You can start it by calling the following. {{< figures/code >}} ```zsh zmodload zsh/zprof ``` {{< /figures/code >}} 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. :) [dotfiles]: https://github.com/erynofwales/dotfiles [debug-zsh]: https://collectednotes.com/gillchristian/debugging-zsh-init-times