---
title: Profiling zsh setup with zprof
author: Victor Cobos
tags: Zsh, OhMyZSH
published_at: '2024-03-22T16:15:00+01:00'
updated_at: '2024-07-24T11:27:10+02:00'
canonical_url: https://www.dotruby.com/articles/profiling-zsh-setup-with-zprof
---

# Profiling zsh setup with zprof

Optimize your zsh setup by profiling with zprof. This guide shows you how to identify and eliminate performance bottlenecks in your .zshrc file, ensuring faster startup times and a smoother shell experience.

Leveraging frameworks like [oh-my-zsh](https://ohmyz.sh) can enrich your shell experience, but overloading it with plugins might slow things down. Keeping your `.zshrc` file lean can significantly enhance startup times and overall performance. Profiling your shell is a good start to figuring out what is slowing it down.

[Zprof](https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fzprof-Module) is a utility that comes packaged with zsh, which you can use to profile your zsh script.
Add the following to the top of your `.zshrc` file to load zprof:

```bash
if [[ -n "$ZSH_DEBUGRC" ]]; then
  zmodload zsh/zprof
fi
```

And this at the bottom:

```bash
if [[ -n "$ZSH_DEBUGRC" ]]; then
  zprof
fi
```

To profile your `.zshrc` script and print a summary of all the commands run during your shell startup and the time it takes to execute them run this:

```bash
time ZSH_DEBUGRC=1 zsh -i -c exit
```

Recommendation would be to put this in an alias to make everything more comfortable.
Running the command will print something like this:

![](https://github.com/dotruby/dotruby-content/assets/3856862/0169e2ee-9a41-4f0d-a1b3-3233d3e42c3a)

If you forget the command, you can always create an alias:

```bash
# -------------------------------------------------------------------
# Debug zsh startup time
# -------------------------------------------------------------------

alias zsh_zprof=time ZSH_DEBUGRC=1 zsh -i -c exit
```

This approach will reveal which commands are the most time-consuming to load, setting you on the path to efficient customization. Happy profiling!
