Skip to content

Commit

Permalink
Shave off another ~18ms off zsh startup time
Browse files Browse the repository at this point in the history
Running `brew --prefix` is slow. Checking whether file exists with `-r`
is slower than `-e`. Avoid double sourcing configuration if it's in two
locations.

Before:
      φ for i in $(seq 0 10); do time /bin/zsh -i -c exit; done
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.111 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.098 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 94% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 94% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.098 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.097 total
      /bin/zsh -i -c exit  0.05s user 0.05s system 95% cpu 0.098 total

After:
      φ for i in $(seq 0 10); do time /bin/zsh -i -c exit; done
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.090 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 96% cpu 0.084 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.082 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.082 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.081 total
      /bin/zsh -i -c exit  0.04s user 0.04s system 95% cpu 0.082 total
  • Loading branch information
mrnugget committed Feb 24, 2021
1 parent 9fcd130 commit 1b394c4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion zsh.d/aliases.Darwin.sh
Expand Up @@ -3,4 +3,4 @@ alias ll="ls -G -l"
alias lh="ls -G -lh"

# Use exuberant-ctags instead of system ctags
alias ctags="`brew --prefix`/bin/ctags"
alias ctags="/usr/local/bin/ctags"
48 changes: 24 additions & 24 deletions zshrc
Expand Up @@ -13,7 +13,7 @@ local machine_name=$(uname)
# Include private stuff that's not supposed to show up
# in the dotfiles repo
local private="${HOME}/.zsh.d/private.sh"
if [ -r ${private} ]; then
if [ -e ${private} ]; then
. ${private}
fi

Expand Down Expand Up @@ -144,11 +144,11 @@ bindkey '^E' end-of-line
#########

local aliasfile="${HOME}/.zsh.d/aliases.${machine_name}.sh"
if [ -r ${aliasfile} ]; then
if [ -e ${aliasfile} ]; then
source ${aliasfile}
fi

if which exa &> /dev/null; then
if type exa &> /dev/null; then
alias ls=exa
fi
alias lls='ls -lh --sort=size --reverse'
Expand Down Expand Up @@ -278,7 +278,7 @@ fi
local dir_info="%{$dir_info_color%}%(5~|%-1~/.../%2~|%4~)%{$reset_color%}"
# local promptnormal="%{$fg_bold[black]%}λ %{$reset_color%}"
local promptnormal="φ %{$reset_color%}"
local promptjobs="%{$fg_bold[red]%}λ %{$reset_color%}"
local promptjobs="%{$fg_bold[red]%}φ %{$reset_color%}"

PROMPT='${dir_info}$(git_prompt_info) %(1j.$promptjobs.$promptnormal)'

Expand Down Expand Up @@ -353,7 +353,7 @@ toggle_colors() {
set_fzf_default_opts
}

if which nvim &> /dev/null; then
if type nvim &> /dev/null; then
alias vim='nvim'
export EDITOR='nvim'
export PSQL_EDITOR='nvim -c"set filetype=sql"'
Expand All @@ -365,7 +365,7 @@ else
fi

local envfile="${HOME}/.zsh.d/env.${machine_name}.sh"
if [ -r ${envfile} ]; then
if [ -e ${envfile} ]; then
. ${envfile}
fi

Expand All @@ -380,13 +380,13 @@ export KEYTIMEOUT=1
export PATH="/usr/local/bin:$PATH"

# asdf
# if [ -f /usr/local/opt/asdf/asdf.sh ]; then
# source /usr/local/opt/asdf/asdf.sh
# fi
#
if [ -f ~/.asdf/asdf.sh ]; then
source ~/.asdf/asdf.sh
if [ -e /usr/local/opt/asdf/asdf.sh ]; then
source /usr/local/opt/asdf/asdf.sh
fi
#
# if [ -e ~/.asdf/asdf.sh ]; then
# source ~/.asdf/asdf.sh
# fi

# Encoding problems with gem
export LC_ALL=en_US.UTF-8
Expand All @@ -404,7 +404,7 @@ export PATH="$GOBIN:$PATH"
export PATH="/usr/local/heroku/bin:$PATH"

# direnv
if which direnv &> /dev/null; then
if type direnv &> /dev/null; then
eval "$(direnv hook zsh)"
fi

Expand All @@ -413,18 +413,18 @@ fi
if [ -e /usr/local/opt/fzf/shell/completion.zsh ]; then
source /usr/local/opt/fzf/shell/key-bindings.zsh
source /usr/local/opt/fzf/shell/completion.zsh
else
# fzf via local installation
if [ -e ~/.fzf ]; then
source ~/.fzf/shell/key-bindings.zsh
source ~/.fzf/shell/completion.zsh
if [[ ! "$PATH" == *$HOME.fzf/bin* ]]; then
export PATH="$PATH:$HOME/.fzf/bin"
fi
fi
fi

# fzf via local installation
if [[ ! "$PATH" == *$HOME.fzf/bin* ]]; then
export PATH="$PATH:$HOME/.fzf/bin"
fi
if [ -e ~/.fzf ]; then
source ~/.fzf/shell/key-bindings.zsh
# source ~/.fzf/shell/completion.zsh
fi

if which fzf &> /dev/null && which rg &> /dev/null; then
if type fzf &> /dev/null && type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*" --glob "!vendor/*"'
export FZF_CTRL_T_COMMAND='rg --files --hidden --follow --glob "!.git/*" --glob "!vendor/*"'
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND"
Expand All @@ -438,7 +438,7 @@ fi

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

if which bat &> /dev/null; then
if type bat &> /dev/null; then
set_bat_theme
alias cat=bat
fi
Expand Down

0 comments on commit 1b394c4

Please sign in to comment.