Ohmyzsh: chruby plugin is slow

Created on 13 Feb 2016  ·  3Comments  ·  Source: ohmyzsh/ohmyzsh

Removing the chruby plugin and adding chruby to my .zshrc manually took 500ms off my terminal startup time.

Most helpful comment

I'm happy with this fix so closing, thanks @T0mK0!

All 3 comments

I can reproduce on my OS X 10.9.5 machine.

+ 1455372625.828910 /Users/janke/.oh-my-zsh/oh-my-zsh.sh:81> plugin=chruby
+ 1455372625.828954 /Users/janke/.oh-my-zsh/oh-my-zsh.sh:82> [ -f /Users/janke/.oh-my-zsh-custom/plugins/chruby/chruby.plugin.zsh ']'
+ 1455372625.829008 /Users/janke/.oh-my-zsh/oh-my-zsh.sh:84> [ -f /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh ']'
+ 1455372625.829074 /Users/janke/.oh-my-zsh/oh-my-zsh.sh:85> source /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh
+ 1455372625.829375 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:17> alias 'rubies=chruby'
+ 1455372625.829660 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:36> _ruby-build_installed
+ 1455372625.829715 _ruby-build_installed:1> whence ruby-build
+ 1455372625.830336 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:66> _homebrew-installed
+ 1455372625.830387 _homebrew-installed:1> whence brew
+ 1455372625.830445 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:66> _chruby-from-homebrew-installed
+ 1455372625.831099 _chruby-from-homebrew-installed:1> brew --prefix chruby
+ 1455372626.053828 _chruby-from-homebrew-installed:1> [ -r /usr/local/opt/chruby ']'
+ 1455372626.054501 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:67> brew --prefix chruby
+ 1455372626.269022 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:67> source /usr/local/opt/chruby/share/chruby/chruby.sh
...
+ 1455372626.271227 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:68> brew --prefix chruby
+ 1455372626.494185 /Users/janke/.oh-my-zsh/plugins/chruby/chruby.plugin.zsh:68> source /usr/local/opt/chruby/share/chruby/auto.sh

Most of its time is being spent on brew --prefix chruby calls, of which it's doing up to three. The brew command is a ruby program, and not fast. Not something to call repeatedly during startup. At the least, the chruby plugin should call brew --prefix chruby once and cache the result in a variable to avoid the redundant calls. Better yet, switch to using plain brew --prefix and construct the path to chruby in zsh with $(brew --prefix)/opt/chruby. The plain brew --prefix call is optimized, and takes only around 15 msec on a fast system.

For future reference, you can do profiling like this yourself to diagnose performance problems:

Stick this at the beginning of you ~/.zshrc.

# Debugging prompt with timestamp for profiling
PS4=$'+ %D{%s.%6.} %N:%i> '

Then run zsh -lx 2>zsh-startup.log and do exit as the first command in the resulting shell that opens. You'll end up with a timestamped trace of your startup sequence. That will help tell you which parts are taking so long. You can stick it in a spreadsheet and diff the timestamps in subsequent lines to get execution times to make it easier. Or scrub any passwords or tokens from it and post it as a gist if you need help analyzing it.

I'm happy with this fix so closing, thanks @T0mK0!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrgaolei picture mrgaolei  ·  3Comments

leongaban picture leongaban  ·  3Comments

faxotherapy picture faxotherapy  ·  3Comments

robsonpeixoto picture robsonpeixoto  ·  3Comments

oskargicast picture oskargicast  ·  3Comments