5

My Zsh is super slow inside a certain Git repo of mine. When I Google "zsh git slow", I get a bunch of results about Git autocompletion being slow, but autocompletion isn't necessarily my problem; it's everything.

I tried removing all plugins and that, strangely, didn't do anything at all when I opened a new shell. Zsh would still do Git stuff inside my Git repo.

I found this snippet on this page:

function git_prompt_info() {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"
}

That made everything fast again, but it also gave me a prompt that looks like this:

➜  snip git:(master

Note the missing right parenthesis. That's kind of lame. Plus the whole thing just seems like a hack I shouldn't have to do.

There's also this promising-looking SU question, but the links on the accepted answer are dead.

How can I get my Zsh not to be slow inside a Git repo?

2
  • Can you link us to the SU question you mention?
    – slhck
    Sep 19, 2012 at 15:42
  • Also, What did you have in your prompt when things were slow (before your snippet)?
    – studgeek
    Oct 9, 2012 at 12:01

5 Answers 5

5

You can execute following command to totally disable git status feature.

git config --global oh-my-zsh.hide-status 1

Or adding the following line into your ~/.zshrc.

DISABLE_UNTRACKED_FILES_DIRTY="true"
4

To trace the shell commands which are invoked while it is slow, you can run: set -x or add into your startup files. It will show you all commands, including the one responsible for autocompletion.

If you believe some git commands are slow you may define some extra variables such as:

exports GIT_TRACE=1

To see more examples, see: How can I debug git/git-shell related problems?

1
  • should we do exports GIT_TRACE=0?
    – alper
    Aug 1, 2023 at 20:20
2

I have removed zsh-autosuggestions as a plugin and then it was faster. In my case it had nothing to do with git.

1
  • -1 removing plugins obviously makes loading faster Mar 20, 2023 at 9:58
1

It's not that autocompletion is slow, it's that autocompletion makes every command seem slow because you are waiting for it to source stuff. Trying commenting out bash_completion completely in your zsh dot files.

1
  • 1
    There doesn't seem to be anything relevant there to comment out. Oct 7, 2012 at 0:52
0

You can try confirming the source of your slowness with zprof. Add this to your ~/.zshrc (or equivalent):

zmodload zsh/zprof

then run zprof after each command to get a summary. In my case, it was a totally unrelated plugin that was causing the slowness.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .