Skip to content

Instantly share code, notes, and snippets.

@dmmulroy
Created January 16, 2024 05:41
Show Gist options
  • Save dmmulroy/4429750e4c210d82e1799cb3df7e47e7 to your computer and use it in GitHub Desktop.
Save dmmulroy/4429750e4c210d82e1799cb3df7e47e7 to your computer and use it in GitHub Desktop.
Profiling my shells startup time

Shell Benchmarking

Initial

$SHELL -i -c exit  0.42s user 0.10s system 63% cpu 0.821 total
$SHELL -i -c exit 0.42s user 0.10s system 65% cpu 0.792 total
$SHELL -i -c exit  0.42s user 0.10s system 60% cpu 0.861 total
$SHELL -i -c exit 0.42s user 0.10s system 65% cpu 0.795 total
$SHELL -i -c exit  0.42s user 0.09s system 61% cpu 0.838 total
$SHELL -i -c exit 0.42s user 0.10s system 62% cpu 0.823 total
$SHELL -i -c exit  0.43s user 0.10s system 66% cpu 0.797 total
$SHELL -i -c exit 0.42s user 0.10s system 63% cpu 0.807 total
$SHELL -i -c exit  0.42s user 0.09s system 64% cpu 0.789 total
$SHELL -i -c exit 0.42s user 0.09s system 64% cpu 0.796 total

Removing export GPG_TTY=$(tty)

$SHELL -i -c exit  0.42s user 0.10s system 66% cpu 0.792 total
$SHELL -i -c exit 0.42s user 0.09s system 65% cpu 0.787 total
$SHELL -i -c exit  0.42s user 0.09s system 63% cpu 0.801 total
$SHELL -i -c exit 0.42s user 0.09s system 65% cpu 0.786 total
$SHELL -i -c exit  0.42s user 0.09s system 64% cpu 0.788 total
$SHELL -i -c exit 0.42s user 0.09s system 64% cpu 0.794 total
$SHELL -i -c exit  0.42s user 0.09s system 64% cpu 0.788 total
$SHELL -i -c exit 0.42s user 0.09s system 63% cpu 0.803 total
$SHELL -i -c exit  0.42s user 0.09s system 64% cpu 0.792 total
$SHELL -i -c exit 0.42s user 0.09s system 65% cpu 0.783 total

Notes: Very minor change, though we're removing it b/c I can't remember why I had it in the first place.

Removing test -r $HOME/.opam/opam-init/init.zsh && . $HOME/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true

$SHELL -i -c exit  0.43s user 0.10s system 64% cpu 0.812 total
$SHELL -i -c exit 0.42s user 0.09s system 64% cpu 0.789 total
$SHELL -i -c exit  0.42s user 0.09s system 65% cpu 0.783 total
$SHELL -i -c exit 0.42s user 0.10s system 62% cpu 0.837 total
$SHELL -i -c exit  0.42s user 0.09s system 65% cpu 0.786 total
$SHELL -i -c exit 0.42s user 0.10s system 64% cpu 0.795 total
$SHELL -i -c exit  0.42s user 0.09s system 66% cpu 0.772 total
$SHELL -i -c exit 0.42s user 0.09s system 65% cpu 0.776 total
$SHELL -i -c exit  0.42s user 0.09s system 63% cpu 0.800 total
$SHELL -i -c exit 0.42s user 0.09s system 62% cpu 0.814 total

Notes: Very minor change, I'm going to leave this for now until I'm fully migrated to using nix dev envs for OCaml projects.

Removing ssh-agent stuff

eval "$(ssh-agent -s)" > /dev/null 2>&1
ssh-add  --apple-use-keychain ~/.ssh/id_ed25519 > /dev/null 2>&1
ssh-add  --apple-use-keychain ~/.ssh/id_ed25519_skolem > /dev/null 2>&1
$SHELL -i -c exit  0.18s user 0.09s system 62% cpu 0.441 total
$SHELL -i -c exit 0.17s user 0.09s system 61% cpu 0.423 total
$SHELL -i -c exit  0.17s user 0.08s system 61% cpu 0.418 total
$SHELL -i -c exit 0.17s user 0.09s system 59% cpu 0.435 total
$SHELL -i -c exit  0.17s user 0.09s system 52% cpu 0.500 total
$SHELL -i -c exit 0.17s user 0.09s system 59% cpu 0.436 total
$SHELL -i -c exit  0.17s user 0.08s system 60% cpu 0.422 total
$SHELL -i -c exit 0.17s user 0.08s system 60% cpu 0.424 total
$SHELL -i -c exit  0.17s user 0.08s system 57% cpu 0.445 total
$SHELL -i -c exit 0.17s user 0.09s system 61% cpu 0.421 total

Notes: Significant difference! This will be removed going forward

Removing custom functions

# functions
# fvim -> find and open a file in vim
function fvim() {
    if [[ $# -eq 0 ]]; then
        fd -t f | fzf --header "Open File in Vim" --preview "bat --color=always {}" | xargs nvim
    else
        fd -t f | fzf --header "Open File in Vim" --preview "bat --color=always {}" -q "$@" | xargs nvim
    fi
}

# vim -> open vim in the current directory or open the target file
function vim() {
    if [[ $# -eq 0 ]]; then
        nvim .
    else
        nvim "$@"
    fi
}

function ghp() {
    echo "$1" |sed 's/\(github\)/personal.\1/'
}
$SHELL -i -c exit  0.18s user 0.09s system 60% cpu 0.456 total
$SHELL -i -c exit 0.18s user 0.09s system 58% cpu 0.445 total
$SHELL -i -c exit  0.17s user 0.09s system 58% cpu 0.442 total
$SHELL -i -c exit 0.17s user 0.09s system 58% cpu 0.448 total
$SHELL -i -c exit  0.17s user 0.08s system 59% cpu 0.427 total
$SHELL -i -c exit 0.17s user 0.09s system 56% cpu 0.461 total
$SHELL -i -c exit  0.17s user 0.09s system 60% cpu 0.430 total
$SHELL -i -c exit 0.17s user 0.09s system 60% cpu 0.422 total
$SHELL -i -c exit  0.17s user 0.09s system 60% cpu 0.422 total
$SHELL -i -c exit 0.17s user 0.09s system 58% cpu 0.443 total

Notes: No significant difference. Will keep for now (but remove ghp)

Removing Bun completions

[ -s "/Users/dillon/.bun/_bun" ] && source "/Users/dillon/.bun/_bun"
$SHELL -i -c exit  0.18s user 0.09s system 60% cpu 0.444 total
$SHELL -i -c exit 0.17s user 0.08s system 60% cpu 0.426 total
$SHELL -i -c exit  0.17s user 0.08s system 60% cpu 0.424 total
$SHELL -i -c exit 0.17s user 0.09s system 59% cpu 0.432 total
$SHELL -i -c exit  0.17s user 0.09s system 60% cpu 0.424 total
$SHELL -i -c exit 0.17s user 0.09s system 60% cpu 0.427 total
$SHELL -i -c exit  0.17s user 0.09s system 57% cpu 0.448 total
$SHELL -i -c exit 0.17s user 0.09s system 57% cpu 0.444 total
$SHELL -i -c exit  0.17s user 0.09s system 57% cpu 0.455 total
$SHELL -i -c exit 0.17s user 0.08s system 59% cpu 0.427 total

Notes: Minor improvement, maybe ~10-20ms

Remove unneeded exports (to be replaced by nix dev envs)

# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

# pnpm
export PNPM_HOME="/Users/dillon/Library/pnpm"
case ":$PATH:" in
  *":$PNPM_HOME:"*) ;;
  *) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end

# For compilers to find zlib you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"

# For pkg-config to find zlib you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"
$SHELL -i -c exit  0.18s user 0.09s system 60% cpu 0.451 total
$SHELL -i -c exit 0.17s user 0.08s system 60% cpu 0.422 total
$SHELL -i -c exit  0.17s user 0.08s system 60% cpu 0.420 total
$SHELL -i -c exit 0.17s user 0.09s system 60% cpu 0.421 total
$SHELL -i -c exit  0.17s user 0.09s system 60% cpu 0.426 total
$SHELL -i -c exit 0.17s user 0.08s system 59% cpu 0.427 total
$SHELL -i -c exit  0.17s user 0.09s system 60% cpu 0.427 total
$SHELL -i -c exit 0.17s user 0.08s system 58% cpu 0.435 total
$SHELL -i -c exit  0.17s user 0.08s system 59% cpu 0.429 total
$SHELL -i -c exit 0.17s user 0.08s system 59% cpu 0.432 total

Notes: No meaningful difference, but removing them in favor of nix

Remove fnm

export PATH="/home/$USER/.local/share/fnm:$PATH"
eval "`fnm env`"
$SHELL -i -c exit  0.20s user 0.09s system 100% cpu 0.282 total
$SHELL -i -c exit 0.19s user 0.08s system 101% cpu 0.264 total
$SHELL -i -c exit  0.20s user 0.09s system 99% cpu 0.293 total
$SHELL -i -c exit 0.19s user 0.08s system 100% cpu 0.273 total
$SHELL -i -c exit  0.19s user 0.08s system 100% cpu 0.267 total
$SHELL -i -c exit 0.19s user 0.08s system 100% cpu 0.267 total
$SHELL -i -c exit  0.19s user 0.08s system 100% cpu 0.269 total
$SHELL -i -c exit 0.19s user 0.08s system 99% cpu 0.272 total
$SHELL -i -c exit  0.19s user 0.08s system 100% cpu 0.268 total
$SHELL -i -c exit 0.19s user 0.08s system 101% cpu 0.265 total

Notes: Another 50% reduction!! Will be removed in favor of nix dev envs

Removing oh_my_zsh plugins, part 1

## Before
 plugins=(git z fnm node npm yarn brew zsh-autosuggestions zsh-syntax-highlighting)

## After
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)
$SHELL -i -c exit  0.09s user 0.07s system 99% cpu 0.155 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.138 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.139 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.137 total
$SHELL -i -c exit  0.08s user 0.06s system 98% cpu 0.141 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.137 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.141 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.138 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.139 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.140 total

Notes: Another 50% reduction, LFG

Removing oh_my_zsh plugins, part 2

# Before
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)

# After
plugins=(git z zsh-syntax-highlighting)
$SHELL -i -c exit  0.09s user 0.06s system 99% cpu 0.152 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.136 total
$SHELL -i -c exit  0.08s user 0.06s system 101% cpu 0.135 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.136 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.137 total
$SHELL -i -c exit 0.08s user 0.06s system 98% cpu 0.139 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.139 total
$SHELL -i -c exit 0.08s user 0.06s system 98% cpu 0.140 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.136 total
$SHELL -i -c exit 0.08s user 0.06s system 99% cpu 0.139 total

Notes: Negligible improvements, will keep zsh-autosuggestions for DX

Removing oh_my_zsh plugins, part 3

# Before
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)

# After
plugins=(git z zsh-autosuggestions)
$SHELL -i -c exit  0.09s user 0.07s system 99% cpu 0.152 total
$SHELL -i -c exit 0.07s user 0.06s system 100% cpu 0.131 total
$SHELL -i -c exit  0.07s user 0.06s system 101% cpu 0.129 total
$SHELL -i -c exit 0.08s user 0.06s system 99% cpu 0.135 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.133 total
$SHELL -i -c exit 0.07s user 0.06s system 101% cpu 0.130 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.133 total
$SHELL -i -c exit 0.07s user 0.06s system 100% cpu 0.129 total
$SHELL -i -c exit  0.07s user 0.06s system 99% cpu 0.133 total
$SHELL -i -c exit 0.07s user 0.06s system 99% cpu 0.132 total

Notes: Negligible improvements, will keep zsh-syntax-highlighting for DX

Removing oh_my_zsh plugins, part 4

# Before
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)

# After
plugins=(z zsh-autosuggestions zsh-syntax-highlighting)
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.145 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.130 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.131 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.06s system 101% cpu 0.133 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.133 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.130 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.133 total
$SHE```LL -i -c exit 0.08s user 0.06s system 102% cpu 0.129 total

Notes: Negligible improvements, will keep git plugin for convenience

## Removing oh_my_zsh plugins, part 5

```sh
# Before
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)

# After
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
$SHELL -i -c exit  0.09s user 0.06s system 99% cpu 0.151 total
$SHELL -i -c exit 0.08s user 0.06s system 98% cpu 0.138 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.136 total
$SHELL -i -c exit 0.08s user 0.06s system 100% cpu 0.135 total
$SHELL -i -c exit  0.08s user 0.06s system 98% cpu 0.141 total
$SHELL -i -c exit 0.08s user 0.06s system 99% cpu 0.139 total
$SHELL -i -c exit  0.08s user 0.06s system 99% cpu 0.140 total
$SHELL -i -c exit 0.08s user 0.06s system 99% cpu 0.137 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.137 total
$SHELL -i -c exit 0.08s user 0.06s system 97% cpu 0.138 total

Notes: Negligible improvements, will keep git plugin for convenience

Removing oh_my_zsh altogether 😱

$SHELL -i -c exit  0.04s user 0.03s system 91% cpu 0.076 total
$SHELL -i -c exit 0.03s user 0.02s system 91% cpu 0.055 total
$SHELL -i -c exit  0.03s user 0.02s system 91% cpu 0.055 total
$SHELL -i -c exit 0.03s user 0.02s system 92% cpu 0.054 total
$SHELL -i -c exit  0.03s user 0.02s system 91% cpu 0.054 total
$SHELL -i -c exit 0.03s user 0.02s system 90% cpu 0.054 total
$SHELL -i -c exit  0.03s user 0.02s system 91% cpu 0.054 total
$SHELL -i -c exit 0.03s user 0.02s system 92% cpu 0.054 total
$SHELL -i -c exit  0.03s user 0.02s system 92% cpu 0.054 total
$SHELL -i -c exit 0.03s user 0.02s system 90% cpu 0.055 total

Notes: Need I say anything? Maybe time to check out fish

Removing starship.rs

export STARSHIP_CONFIG=~/.config/starship/config.toml
export STARSHIP_CACHE=~/.config/starship/cache
eval "$(starship init zsh)"
$SHELL -i -c exit  0.03s user 0.02s system 92% cpu 0.054 total                      $SHELL -i -c exit 0.02s user 0.01s system 93% cpu 0.036 total
$SHELL -i -c exit 0.02s user 0.01s system 93% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 93% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 93% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 92% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 89% cpu 0.037 total
$SHELL -i -c exit 0.02s user 0.01s system 94% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 93% cpu 0.034 total
$SHELL -i -c exit 0.02s user 0.01s system 90% cpu 0.035 total

Notes: We get ~20ms improvement. At this point, I'm going to keep starship because I'm a basic bitch and love my prompt_line

Final benchmarks

Minimal oh-my-zsh plugins + starship

$SHELL -i -c exit  0.09s user 0.06s system 99% cpu 0.151 total
$SHELL -i -c exit  0.08s user 0.05s system 101% cpu 0.132 total
$SHELL -i -c exit  0.08s user 0.05s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.05s system 95% cpu 0.139 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.134 total
$SHELL -i -c exit  0.08s user 0.05s system 101% cpu 0.132 total
$SHELL -i -c exit  0.08s user 0.05s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.05s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.06s system 100% cpu 0.133 total
$SHELL -i -c exit  0.08s user 0.06s system 101% cpu 0.132 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment