1

As of yesterday, 2 things have slowed in zsh:

  1. prompt is slow to load (in git dirs only)
  2. tab auto completion is slow (like git checkout some-bra[tab] takes longer than it used to)

One thought I had - the other day I needed to pull a remote branch that had not been merged into anything yet, and I used git switch per the most recent up on this post. I have since deleted that branch locally but zsh is still slow in git repos (even other repos). My thinking is that maybe zsh is checking some remote stuff when figuring out autocomplete / building the prompt.

relevant (as far as I can tell) sections of ~/.zshrc:

__git_files () {
    _wanted files expl 'local files' _files
}

autoload -Uz vcs_info
precmd() { vcs_info }

zstyle ':vcs_info:git:*' formats '(%b)'
zstyle ':vcs_info:*' enable git

zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr ' *'
zstyle ':vcs_info:*' stagedstr ' +'
zstyle ':vcs_info:git:*' formats       '(%b%u%c)'
zstyle ':vcs_info:git:*' actionformats '(%b|%a%u%c)'

function git_branch_name() {
  branch=$(git symbolic-ref HEAD 2> /dev/null | awk 'BEGIN{FS="/"} {print $NF}')
  if [[ $branch == "" ]];
  then
    :
  else
    echo '- ('$branch')'
  fi
}

setopt prompt_subst
PROMPT=$'
%F{white}\u256d %~ ${vcs_info_msg_0_}
\u2570 %# %f'

setopt auto_cd

autoload -U compinit; compinit
# zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

# 0 -- vanilla completion (abc => abc)
# 1 -- smart case completion (abc => Abc)
# 2 -- word flex completion (abc => A-big-Car)
# 3 -- full flex completion (abc => ABraCadabra)
zstyle ':completion:*' matcher-list '' \
  'm:{a-z\-}={A-Z\_}' \
  'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
  'r:|?=** m:{a-z\-}={A-Z\_}'

full ~/.zshrc contents:

if [[ "$ZPROF" = true ]]; then
  zmodload zsh/zprof
fi

# printf '\n%.0s' {1..100}

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$PATH:$HOME/custom-git-commands/

export MANPAGER="vim -M +MANPAGER -c 'syntax off' -c 'set foldlevel=9999' -c 'set number relativenumber' -"

plugins=(git wd zshmarks)

export ZSH_COMPDUMP=$ZSH/cache/.zcompdump-$HOST

# User configuration

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"

HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=5000
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt incappendhistory
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups

# uses homebrew-installed GNU coreutils' ls
alias ls='gls --group-directories-first -F -a --color=never'

alias gm="jump"
alias sm="bookmark"
alias dm="deletemark"
alias pm="showmarks"

alias chrome="open -a 'Google Chrome'"
alias copypath="pwd|pbcopy"

alias python="python3"

function chpwd_do_ls () {
    ls
}
chpwd_functions=( chpwd_do_ls )

declare -a SCOLDS
SCOLDS=(
  "Everything is an instruction."
  "Remember the scream test."
    "rm is a dangerous command."
    "Read the error message."
  "Read the docs."
  "Generally, not trying too hard will result in good enough code."
)
alias clear='echo ${SCOLDS[ $RANDOM % ${#SCOLDS[@]} + 1 ]}'
alias c='clear'

alias vimz='vim ~/.zshrc'
alias vimv='vim ~/.vimrc'

alias sc='source ~/.zshrc'
alias ez='exec zsh'

alias ..='cd ..'

alias confgit='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'

alias ga='git add .'
alias gcm='git commit -m'
alias grao='git remote add origin'
alias gp='git push'
alias gst='git status'
alias gpuo='git push --set-upstream origin'
alias glo='git log --oneline'
alias gvl='git vlog'
alias gvd='git vdiff'
alias grb='git rebase'
alias gcb='git checkout -b'
alias gco='git checkout'

precmd() { print "" }

__git_files () {
    _wanted files expl 'local files' _files
}

autoload -Uz vcs_info
precmd() { vcs_info }

zstyle ':vcs_info:git:*' formats '(%b)'
zstyle ':vcs_info:*' enable git

zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr ' *'
zstyle ':vcs_info:*' stagedstr ' +'
zstyle ':vcs_info:git:*' formats       '(%b%u%c)'
zstyle ':vcs_info:git:*' actionformats '(%b|%a%u%c)'

function git_branch_name() {
  branch=$(git symbolic-ref HEAD 2> /dev/null | awk 'BEGIN{FS="/"} {print $NF}')
  if [[ $branch == "" ]];
  then
    :
  else
    echo '- ('$branch')'
  fi
}

setopt prompt_subst
PROMPT=$'
%F{white}\u256d %~ ${vcs_info_msg_0_}
\u2570 %# %f'

setopt auto_cd

autoload -U compinit; compinit
# zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

# 0 -- vanilla completion (abc => abc)
# 1 -- smart case completion (abc => Abc)
# 2 -- word flex completion (abc => A-big-Car)
# 3 -- full flex completion (abc => ABraCadabra)
zstyle ':completion:*' matcher-list '' \
  'm:{a-z\-}={A-Z\_}' \
  'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
  'r:|?=** m:{a-z\-}={A-Z\_}'

timezsh() {
  shell=${1-$SHELL}
  for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
profzsh() {
  shell=${1-$SHELL}
  ZPROF=true $shell -i -c exit
}

if [[ "$ZPROF" = true ]]; then
  zprof
fi
Aaron Parisi
  • 464
  • 7
  • 15
  • Your prompt does not execute any command, and the `precmd` looks harmless. I don't see why it should be slow. What **does** look strange to me: (1) Your prompt refers to the variable `vcs_info_msg_0_`, but you don't set it anywhere. (2) Your function `git_branch_name` looks like it might take more time depending on the operating system you are using, but where do you use it? – user1934428 Nov 17 '22 at 10:05
  • good questions - `git_branch_name` is an alternative function that I was trying out, I left it in there for demonstrative purposes. As for `vsc_info_msg_0_`, yea I'm not sure... at one point I had `...${ some_vcs_thing_here_ }...` in the prompt which would pull the vcs info but I don't remember what that was :/ – Aaron Parisi Nov 17 '22 at 17:14
  • 1
    `precmd() { vcs_info }` populates that variable. See https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Version-Control-Information – Marlon Richert Dec 12 '22 at 10:01

0 Answers0