Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oh-my-zsh slow, but only for certain Git repo

Tags:

git

zsh

People also ask

Is zsh slower than bash?

We can start by profiling raw zsh - it's even faster than raw bash. The first step is to figure out exactly what's taking so long - there are a variety of tools to measure performance, but the most useful will be zsh 's native debug tools.

Does Git work with zsh?

git-prompt.sh is compatible with both Bash and Zsh. Zsh is powerful enough that there are entire frameworks dedicated to making it better.

Why is git status slow?

The first thing to determine is if the poor behavior is due to your machine or to your specific local copy of the repo. The files in your . git folder can affect performance in various ways - settings in . git/config , presence of lfs files, commits that can be garbage collected, etc.


You can add this to your git config and zsh won't check the status anymore

git config --add oh-my-zsh.hide-status 1
git config --add oh-my-zsh.hide-dirty 1

Explanation

There are two central git functions in in lib/git.zsh:

  • git_prompt_info()
  • parse_git_dirty()

Each Method has a git config switch to disable it:

  • oh-my-zsh.hide-status
  • oh-my-zsh.hide-dirty

Some themes create their own git queries and sometimes ignore these flags.


Oh_my_zsh seems to be slow for some repos because it checks the status of the repo after each command. This behaviour can be overridden in the new version of .oh_my_zsh . Just Uncomment the following line in .zshrc:

DISABLE_UNTRACKED_FILES_DIRTY="true"

After this, restart your terminal or run the following:

source ~/.zshrc


It could be the theme calling git and rvm stuff after every command.

For me, changing ZSH_THEME="juanghurtadoto" to ZSH_THEME="miloshadzic" removed the 2 second delay after every command completely.

Themes can be found at https://github.com/robbyrussell/oh-my-zsh/wiki/themes


For me it's slow on VirtualBox (the guest) because I'm using a synced folder. I still want it enabled on OS X (the host) where it's fast enough. Instead of using a local config setting which is stored with the repo and would change it both on the guest and host, I use a global config setting only on the guest:

git config --global --add oh-my-zsh.hide-dirty 1

If I want it just for a single repo:

git config --add oh-my-zsh.hide-dirty 1

There are various way to speed up an oh-my-zsh, as detailed in "zsh starts incredibly slowly", cleaning up the plugin section.

For instance, the blog post "Fix for oh-my-zsh git-svn prompt slowness" mentions the parse_git_dirty function as a potential issue.


I finally figured it out. My project had a rake folder with a ton of files (like 20,000). I have no idea what that folder was there for, but I deleted it, Zsh is no longer slow, and my app still seems to work.


For others coming to this question looking to improve their zsh git latency, the following reduced my latency from 40ms to 4ms:

  1. Compile and install an optimized git-branch-name command:

    git clone https://github.com/notfed/git-branch-name
    cd git-branch-name
    make
    sudo install git-branch-name /usr/local/bin/
    
  2. Add this to your ~/.zshrc:

    function git_prompt_info() {
        ref=$(git-branch-name -q -h 12 -b 64) || return
        echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref}${ZSH_THEME_GIT_PROMPT_CLEAN}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
    }
    

(The -h and -b flags control truncation length for branch names and hashes, respectively.)

With this, I can hold enter and not experience any lag.