Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oh-my-zsh very slow :( #5327

Closed
SebTM opened this issue Aug 20, 2016 · 79 comments
Closed

oh-my-zsh very slow :( #5327

SebTM opened this issue Aug 20, 2016 · 79 comments

Comments

@SebTM
Copy link

SebTM commented Aug 20, 2016

Hello,

I'm new to zsh/oh-my-zsh and installed it the first time on Mac OS X today. My Terminal (iTerm2 and default Mac-Terminal) starts very slow now - I have a real "waiting" time after opening App. Inside the Terminal it's better but also compared to "default bash" - slow. For example, if I only push the enter-key it just takes 1-2 seconds before terminal "responds", or if I press "CMD+V" for paste, I have to wait some seconds.

Used software:

  • Mac OS X - 10.11.6 (El Capitan)
  • ZSH v5.2
  • oh-my-zsh - latest (installed today)

Benchmark (with plugins - see .zshrc - loaded):

/usr/bin/time /usr/local/bin/zsh -i -c exit
4.63 real 0.47 user 0.29 sys

Benachmark (without plugins loaded):

/usr/bin/time /usr/local/bin/zsh -i -c exit
1.38 real 0.24 user 0.13 sys

Here also my ".zshrc"-file:

# Path to your oh-my-zsh installation.
export ZSH=/Users/username/.oh-my-zsh

# Set name of the theme to load.
ZSH_THEME="agnoster"

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
plugins=(git command-not-found copydir copyfile cp history sublime vagrant composer symfony brew osx)

source $ZSH/oh-my-zsh.sh

# Set default-user to remove "user@hostname" from agnoster
DEFAULT_USER="username"

# Load zsh-syntax-highlighting
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# Set correct path for php-5.6
export PATH=/usr/local/php5-5.6.23-20160626-132038/bin:~/.composer/vendor/bin/:$PATH

Is this normal or can it be fixed?

@mcornella
Copy link
Member

mcornella commented Aug 20, 2016

Try running zsh in debug mode: zsh -xv and note where in the terminal freezes. If you use the asciinema tool you'll be able to record it in real time and post it here. asciinema isn't able to record time, it all just looks like a sequencial log with no pauses.

@SebTM
Copy link
Author

SebTM commented Aug 20, 2016

Thanks for your fast reply. I figured out, that "command-not-found" really slows down the start of zsh (on opening new shell), so I removed it as it does not have this overvalue. I also found out, that there is a difference running zsh "normaly" or after sourcing the .zshrc. It takes about double time after resourcing the file.

You cann see the asciinema-video here: https://asciinema.org/a/9h3kd6ngpxnosmdi5ra3totgc

@allanburleson
Copy link

I believe you want to close this if you figured out the problem?

@SebTM
Copy link
Author

SebTM commented Aug 21, 2016

Hmm, not really as it is still slow. What do you say to the benchmark time without plugins? Is it normal?

What about the fact, that benchmark takes double time after sourcing ".zshrc"?

@eduOS
Copy link

eduOS commented Aug 31, 2016

Mine is very very slow. When I open a terminal it takes about 7 seconds to launch the zsh and sometimes only half of the theme can display. What's wrong with it after several updates?

@cewood
Copy link

cewood commented Sep 7, 2016

I'm experiencing a similarly slow startup time to what @eduOS describes, 6-7 seconds to have a usable terminal 👎

@yorch
Copy link

yorch commented Sep 8, 2016

Cleaning the ASL logs (as described here) helps to reduce the startup time

@foxx
Copy link

foxx commented Sep 22, 2016

Turns out my slowness was due to nvm being loaded on this line;

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

I fixed this by using the following alias, and running loadnvm whenever I need it.

alias loadnvm=". /usr/local/opt/nvm/nvm.sh"

(thank you @mcornella for pointing out debug switches, doh!)

@SebTM
Copy link
Author

SebTM commented Sep 22, 2016

So is it fixed - or how can I fix it on my device?

@foxx
Copy link

foxx commented Sep 22, 2016

@SebTM can you paste a copy of your .zshrc please? Also can you try with a clean .zshrc and then also with a fresh install of ohmyzsh? This should at least help narrow down where the problem might be

@nicohvi
Copy link

nicohvi commented Sep 29, 2016

This might be unrelated, but I'm seeing the same on a fresh install of ohmysh on Ubuntu on Windows 10. Works like a charm on my OS X install btw, great job 👍

Zsh-version: 5.0.2
Ohmyzsh-version: latest

This is the entire content of my .zshrc:

ZSH=/home/<username>/.oh-my-zsh
source $ZSH/oh-my-zsh.sh

The shell takes about 7 seconds to load whenever I source ohmysh.sh.

Update
After doing some more research, it's the sourcing of config files that takes so long.

for config_file ($ZSH/lib/*.zsh);do
  custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  [ -f "${custom_config_file" ] && config_file="${custom_config_file}
  source $config_file # this takes about six seconds
done

Update 2
It seems history.zsh might be the culprit. When I remove it from the lib folder the boot time goes down to about 2 seconds (which I can live with).

@ShawnLinLoveLife
Copy link

ShawnLinLoveLife commented Oct 7, 2016

# Path to your oh-my-zsh installation.
export ZSH=/Users/shawn/.oh-my-zsh

ZSH_THEME="agnoster"

plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
. /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh

This is my zshrc, and I think it is the last line that makes it slowly. Any suggestions? Thanks!

. /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh

@mcornella
Copy link
Member

@ShawnLinLoveLife that's a powerline thing. Have a look at their documentation for potential improvements: http://powerline.readthedocs.io/en/latest/troubleshooting.html?highlight=zpython#i-am-suffering-bad-lags-before-displaying-shell-prompt.

@mcornella
Copy link
Member

@nicohvi can you try debugging where in the file it slows down? If you run set -xv; source $ZSH/lib/history.zsh; set +xv you'll get the whole trace.

Pay attention to the particular line where it stops, if it stops at all.

@mcornella
Copy link
Member

@SebTM the asciinema video doesn't capture terminal pauses... You can try disabling plugins one by one and checking the load time with your custom command.

@nicohvi
Copy link

nicohvi commented Oct 10, 2016

Sure thing @mcornella 👍

@froyo-naux
Copy link

zsh -xv > ~/info 2>&1

@austenLacy
Copy link

@nicohvi I also found that it was caused by the history.zsh file. I updated lines

HISTSIZE=10000
SAVEHIST=10000

to only be

HISTSIZE=1000
SAVEHIST=1000

It seems that the issue was that my .zsh_history file was almost 50k lines long with previous commands. Deleting that file also did the trick, though you'll lose all command history you've had.

@chefjuanpi
Copy link

chefjuanpi commented Nov 3, 2016

I have the same insue with zsh in ubuntu in vagrant in a win 10 machine.

I install zsh and oh my zsh today is a really fresh installation.

all works fine out the project folder. with debug mode appears that:

+prompt_git:11> dirty=+prompt_git:11> parse_git_dirty
+parse_git_dirty:1> local 'STATUS='
+parse_git_dirty:2> local FLAGS
+parse_git_dirty:3> FLAGS=( --porcelain )
+parse_git_dirty:4> [[+parse_git_dirty:4> git config --get oh-my-zsh.hide-dirty
+parse_git_dirty:4> [[ '' != 1 ]]
+parse_git_dirty:5> [[ 1 -gt 0 ]]
+parse_git_dirty:6> FLAGS+='--ignore-submodules=dirty'
+parse_git_dirty:8> [[ '' == true ]]
+parse_git_dirty:11> STATUS=+parse_git_dirty:11> STATUS=+parse_git_dirty:11> git status --porcelain '--ignore-submodules=dirty'
+parse_git_dirty:11> tail -n1

and frezze the screem more less 30 sec.

I try to change agnoster to robbyrussell but the problem continue

@przbadu
Copy link

przbadu commented Nov 25, 2016

@foxx Thanks man, I was going crazy with this problem, mine was almost taking 8-10 seconds to load terminal and new tabs and finally creating alias to manually load nvm and removing old lines worked for me

Small tips though, looking at the auto generated code we can also use $(brew --prefix nvm)/nvm.sh

# export NVM_DIR=~/.nvm
# source $(brew --prefix nvm)/nvm.sh
alias loadnvm=". $(brew --prefix nvm)/nvm.sh"

This did fixed my problem with load time, thanks

@gerardbm
Copy link

I had the same problem in my terminal. As a GNU/Linux user, I removed these two lines from the file .zprofile:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

I needed them to use jshint on Sublime Text. Recently I switched to Neovim, so I can remove them.

Now the load time is about 2 seconds.

@9mm
Copy link

9mm commented Dec 15, 2016

Heres a better solution that still lets you call node and npm:

nvm-sh/nvm#539 (comment)

@lu4
Copy link

lu4 commented Jan 25, 2017

@samkugji you've killed the thread with your green mile, cut the crap

@sprig
Copy link

sprig commented Jan 26, 2017

I used a profiling function and found out that 'spectrum.zsh' was taking (in the profiler, which runs slower - but still) several seconds. I replaced it temporarily with an empty file and the startup got much faster (still too slow - IMHO it shouldn't take over half a second - but at least bearable).

@9mm
Copy link

9mm commented Jan 26, 2017 via email

@sprig
Copy link

sprig commented Jan 26, 2017

I don't know. It doesn't seem essential (read the code). it's in $oh-my/lib/spectrum.zsh

@RWOverdijk
Copy link

Slow here as well. I found most of it to be caused by nvm, too.

@T0mK0
Copy link
Contributor

T0mK0 commented Mar 15, 2017

If you use aws plugin , comment out brew invocation in :

.oh-my-zsh/plugins/aws/aws.plugin.zsh

_awscli-homebrew-installed() {
#  brew list awscli &> /dev/null
 true
} 

AND add false to

_homebrew-installed() {
  type brew &> /dev/null
  false
}

So even if you have brew installed ( probably good idea anyway ) , you will save 2 invocations of

brew --prefix awscli
and
brew list awscli

$ time zsh -xv -c exit
exit
+zsh:1> exit
zsh -xv -c exit  0.00s user 0.00s system 55% cpu 0.006 total

My plugins

plugins=(zsh-autosuggestions brew aws kitchen knife osx ruby docker colorize vagrant zsh-syntax-highlighting sudo)

@jesstelford
Copy link

I knocked off about 3s, using this script by @Tyriar & @Stanzilla to defer loading of nvm:

# Defer initialization of nvm until nvm, node or a node-dependent command is
# run. Ensure this block is only run once if .bashrc gets sourced multiple times
# by checking whether __init_nvm is a function.
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(whence -w __init_nvm)" = function ]; then
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
  declare -a __node_commands=('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack')
  function __init_nvm() {
    for i in "${__node_commands[@]}"; do unalias $i; done
    . "$NVM_DIR"/nvm.sh
    unset __node_commands
    unset -f __init_nvm
  }
  for i in "${__node_commands[@]}"; do alias $i='__init_nvm && '$i; done
fi

Make sure you also remove nvm from the plugins list, and remove any other NVM loading code.

This has the benefit of auto-loading nvm the first time you try to run any of the commands in ('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack') 🎉

@skoskie
Copy link

skoskie commented May 7, 2018

The script referenced directly above made the biggest difference for me. After trying everything else in this thread, I still had a 6.9 second load time because I was loading the zsh plugins that depended on nvm, so loading of nvm wasn't really delayed.

Adding this script and removing the relevant zsh plugins reduced the time from 6.9 seconds to 1.2 seconds.

And as you might expect, executing npm or one of the other commands for the first time takes a little longer, but that's a perfectly acceptable trade-off.

@wzrdtales
Copy link

yup lazy loading is also a way to do it, but it might still screw with your performance. For example if you use neovim or other editors with certain extensions. Basically everything that spawns a new shell will suck :/ . Apart from that it should work, for me my hard fork works just perfect and has also eliminated almost all the overhead and loadtime which have been the problem.

https://github.com/wzrdtales/nvm-ng

Small benchmarks of the improvement are here:

wzrdtales/nvm-ng#2

and load it with (the --fast-reuse bit makes the biggest improvement though)

[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" --fast-reuse

Or just manually pull the plugin #6671 and use it.

It is still very sad that the author of nvm is not really willing to replace the very slow npm call which is the reason of all evil with a simple sed. However. all the solutions here should help.

@partounian
Copy link
Contributor

partounian commented Aug 29, 2018

There's also this zsh plugin for nvm which I have been using for some time https://github.com/lukechilds/zsh-nvm

@addozhang
Copy link

addozhang commented Sep 29, 2018

I disable the oc, kubectl, docker plugin and comment the initialization of nvm and sdkman.

Additionally, switch command of Default profile from Login shell to Command with /usr/bin/login -pfq xxx filled. xxx is your username.

It runs fast now.

@endlesslight0
Copy link

My zsh was starting about 10 seconds. After manual upgrade_oh_my_zsh it now flies !

@Tsovak
Copy link

Tsovak commented Jan 19, 2019

brew install moreutils
call zsh -xv 2>&1 | ts -i "%.s" > zsh_startup.log
sort by time sort --field-separator=' ' -r -k1 zsh_startup.log> sorted.log
and see what loaded too slow. For me, it was a ruby plugin which needs a 3 second to loads

@tayyarg
Copy link

tayyarg commented Jan 22, 2019

The issue in my case was the vcs_info which checks the version control status of the current working directory.

1- I've replaced the following line in my active theme redefined.sh-theme under .oh-my-zsh/themes folder:

command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "*"

to

git diff-files --no-ext-diff --quiet || git diff-index --no-ext-diff --quiet --cached HEAD

(This is only good unless you want to take untracked files into account)

2- Set the DISABLE_UNTRACKED_FILES_DIRTY="true" in my .zshrc
3- Ran git config oh-my-zsh.hide-status 1 on the most complicated repo I'd visit at most

By the way, thanks guys for pointing out, zsh -xv helped me a lot to find the problematic line.

Now, switching into folders with complicated repos is much faster.

@travisstaloch
Copy link

If you are using powerlevel9k, make the switch to powerlevel10k which is MUCH faster. I noticed a big speedup from wsl ubuntu 18.04 after switching from 9k to 10k.

@Red-Eyed
Copy link

Hello, same issue. it runs about 10 second and ~6 seconds for each command.
Commenting all in .oh-my-zsh/lib/history.zsh fixed that.

@yaochx
Copy link

yaochx commented Jun 20, 2019

I met the same issue, there were xcode 9.0 and xcode 8.2 in my osx.
once openning iterm2, the title bar occured (xcodebuild), so I uninstall xcode 8.2.
Luckily, it works fine

@tasomaniac
Copy link

command-not-found is really really slow to init.

@wrabit
Copy link

wrabit commented Apr 7, 2020

Hitting ctrl+c and it hangs for while until it terminates the current operation, even if there is nothing to terminate.

Update a mixture of #5327 (comment) and simply git adding and committing my project solved my issue.

@Sunwarul
Copy link

Turns out my slowness was due to nvm being loaded on this line;

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

I fixed this by using the following alias, and running loadnvm whenever I need it.

alias loadnvm=". /usr/local/opt/nvm/nvm.sh"

(thank you @mcornella for pointing out debug switches, doh!)

Thanks, man. This Worked for me. NVM script was taking some time to loaded.

@mcornella
Copy link
Member

mcornella commented May 11, 2020 via email

@ahmadie
Copy link

ahmadie commented Nov 16, 2020

nvm is slow to load and was mading me crazy when i switch to zsh,
alias loadnvm=". /usr/local/opt/nvm/nvm.sh"
fixed the problem though !!

@scratchoo
Copy link

oh-my-zsh is slow on folders with git while fast in other regular folders, we got rid of this issue using:

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

this will disable the Git status prompt in all repositories you have on your machine

Now if I do something like ls the output is immediate, it's unfortunate to not see the git status but a fast terminal is more important than this :)

source of the command above: https://www.stevenrombauts.be/2018/04/disable-git-prompt-in-oh-my-zsh/ (thanks to the author)

@andresdotsh
Copy link

This worked for me.
With macOS Big Sur 11.3, Xcode 12.5, Command Line Tools, and iTerm2 fresh installation.

1. Uninstall oh-my-zsh

Instructions here.

2. Install homebrew

Instructions here.

3. Install git (but with homebrew)

brew install git

4. Install oh-my-zsh again

Instructions here.

That's all!

In my case, the thing was that when I installed the Command Line Tools, a git version was installed.
And apparently there is an issue between that git version and oh-my-zsh.
That was causing a slow startup with the xcodebuild title in the iTerm2 window.

@urbanadventurer
Copy link

This fixed it for me
sudo xcodebuild -license accept

@vinacioo
Copy link

For me the delay was to cd into a folder from $HOME. Fixed by disabling the case sensitive in .zshrc.

@DougPuchalski
Copy link

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

Now it is git config oh-my-zsh.hide-info 1

@avatar-lavventura
Copy link

@DougPuchalski Isn't it for local git repos rather than making changes for all the git repos?

git config oh-my-zsh.hide-info 1

@iambudi
Copy link

iambudi commented Jul 29, 2022

macOS Monterey:
On first launch terminal after desktop login, it's like stuck on xcode build (title bar shows this) for few seconds. sudo xcodebuild -license accept does not solve it.

I don't have nvm installed. Still curious why it so slow.

@iambudi
Copy link

iambudi commented Jul 29, 2022

After investigating, this triggered the issue xcodebuild:
export SDKROOT=$(xcrun -sdk macosx --show-sdk-path).

Solution is by running sudo xcode-select -s /Library/Developer/CommandLineTools as mentioned in here

So this is not problem of omz.
Correction: My bad i have nvm installed as well but it does not trigger issue.

Another finding during investigation is to get brew path using brew --prefix <formula> requires ruby. Change to absolute path make it faster.

@juanarbol
Copy link

I don't know who needs to know this, but in my case -using linux- was the "energy profile". Set the profile as "performance" just solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests