logoalt Hacker News

alkhyesterday at 5:35 AM5 repliesview on HN

Like many other people, I use oh-my-zsh for default setup and that's it. I literally use a single plugin for git and very actively autoload my custom functions to avoid startup delay. With my 384 line config and oh-my-zsh on, here are the results:

$ hyperfine -N "zsh -lc 'exit 0'" "zsh -c 'exit 0'"

Benchmark 1: zsh -lc 'exit 0'

  Time (mean ± σ):      54.5 ms ±   6.3 ms    [User: 10.2 ms, System: 14.3 ms]

  Range (min … max):    38.1 ms …  64.9 ms    78 runs
Benchmark 2: zsh -c 'exit 0'

  Time (mean ± σ):       6.5 ms ±   1.4 ms    [User: 0.8 ms, System: 1.3 ms]

  Range (min … max):     3.9 ms …  14.2 ms    424 runs
It's crazy how their startup time is 380 ms, and I suspect something else might be the reason, not just oh-my-zsh

Replies

simonairyesterday at 10:05 AM

For anyone who cares about zsh startup performance, `zsh4humans` by `romkatv` (author of powerlevel10k) is worth a look: https://github.com/romkatv/zsh4humans

It achieves instant startup by rendering the prompt before the full shell initializes. Since adopting it, I am done fiddling with my shell config and the fact that `zsh4humans` is in maintenance-mode is actually an advantage as it keeps me from wasting time refactoring `zshrc`.

maple3142yesterday at 6:46 AM

I think `zsh -l` start a login shell, which does not load zshrc so oh-my-zsh don't get initialized. Try `zsh -ic exit` and it should load zshrc before executing exit.

That said, the time of `zsh -ic exit` isn't really meaningful metric for measuring the performance of an interactive shell. See https://github.com/romkatv/zsh-bench#how-not-to-benchmark for details.

show 1 reply
archargelodyesterday at 8:02 AM

Better way to benchmark zsh startup time is with zprof. Add this to your ~/.zshrc:

    zmodload zsh/zprof
    .. rest of your zsh config ..
    zprof
And then restart terminal.
jabwdyesterday at 5:39 AM

Trying doing the benchmark in a git repo.

show 1 reply
babyyesterday at 6:07 AM

You should try extract, z, and fzf