Skip to content

Commit

Permalink
zsh: cache brew --prefix output
Browse files Browse the repository at this point in the history
According to hyperfine, this shaved off ~45–50ms on my personal machine.
I expect it will be a more significant savings on my work machine based
on watching `zsh -x exit`.

    λ hyperfine 'zsh -c exit'
    Benchmark 1: zsh -c exit
      Time (mean ± σ):     195.4 ms ±   2.1 ms    [User: 98.4 ms, System: 72.8 ms]
      Range (min … max):   191.8 ms … 199.2 ms    15 runs
    # apply change
    λ hyperfine 'zsh -c exit'
    Benchmark 1: zsh -c exit
      Time (mean ± σ):     148.6 ms ±   2.2 ms    [User: 82.4 ms, System: 50.8 ms]
      Range (min … max):   144.4 ms … 152.4 ms    19 runs

It's interesting to me how much the System cost came down.
  • Loading branch information
benknoble committed Jan 30, 2025
1 parent 959a999 commit fb82448
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion links/zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fi

# brew paths
if "$has_brew" ; then
brew_prefix="$(brew --prefix)"
brew_prefix="$(cat ~/.brew-prefix 2>/dev/null || brew --prefix | tee ~/.brew-prefix)"
pathadd_front "$brew_prefix/bin"
pathadd_front man "$brew_prefix/share/man"
pathadd_front info "$brew_prefix/share/info"
Expand Down

0 comments on commit fb82448

Please sign in to comment.