1. home
  2. terminal
  3. a-zsh-setup-that-starts-in-under-50-ms

A zsh setup that starts in under 50 ms

Theo Lindqvist Terminal 2 mins read 0 comments 18 views

A new terminal tab should be instant. Ours took 640 ms until we measured it, and most of that time went on three plugins we barely used.

Measure before you cut

Add zprof to the top of your .zshrc, open a new tab, and read the table. The top three entries are almost always nvm, a completion system that rebuilds its cache on every start, and a prompt that shells out to git.

Lazy-load the heavy hitters

Language version managers do not need to load until you run node or python. A tiny wrapper function that sources the real script on first use cuts hundreds of milliseconds without changing how you work.

Cache completions once a day

compinit only needs a full security check when the dump file is older than a day. Checking the file age first is the single biggest win on a Mac with many Homebrew completions.

  • Run zprof after every plugin you add.
  • Prefer a compiled prompt such as Starship over a pure-zsh theme.
  • Keep PATH edits in .zprofile so they run once per login.
code
autoload -Uz compinit
if [[ -n ${ZDOTDIR:-$HOME}/.zcompdump(#qN.mh+24) ]]; then
  compinit
else
  compinit -C
fi

Premature optimization is the root of all evil.

Donald Knuth, Structured Programming with go to Statements (1974)

Run hyperfine 'zsh -i -c exit' before and after each change so you are measuring, not guessing.

$ echo "leave a comment"