0

When I open a new terminal it takes a couple seconds for the shell to load, when I open a new pane or window in tmux it might even take a second longer. The delay is about 3 seconds.

I'm using zsh with oh-my-zsh and the ohmyzsh plugins: git, vi-mode, history-substring-search.

My path looks like:

/home/alec/.nvm/versions/node/v14.6.0/bin:/home/alec/.composer/vendor/bin:/home/alec/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/alec/code/bin

Previously I had wondered if having a git repo on the path would be problematic. The final location in that path ~/code/bin used to be ~/bin and there was the .git database inside it. Now the .git directory is in ~/code (which seems to me like it would prevent the shell from looking through it for executables) but this hasn't delivered any performance improvements.

I don't know any other guess-and-check possibilities, or any logical troubleshooting procedures to perform/investigate.

Any suggestions?

8
  • 1
    Never used Zsh before, but since it's a shell and that sounds like a similar problem that you can have on bash...I'm guessing it might be either your zsh config or the plugins/extension you installed for Zsh which slow things down. (you could try with/without them and see the difference in speed to make sure) Jun 1, 2021 at 16:38
  • disabling the plugins (including in "core" ohmyzsh) doesn't seem to deliver any performance improvement
    – alec
    Jun 1, 2021 at 16:46
  • 1
    what about the zsh config file? does using a smaller one/default one change anything? Jun 1, 2021 at 16:49
  • 2
    You could run PS4='%D{%T.%3.} %N:%i> ' script -c 'exec zsh --login -o xtrace', exit, and then look into the typescript file where all the time is spent. Jun 1, 2021 at 16:53
  • 1
    In the current working directory where you started the script command from. See man script Jun 1, 2021 at 17:32

1 Answer 1

0

Add: set -x to the top and set +x to the bottom of ~.zshrc to get a lot of output about what's being run during shell startup. (It's helpful to keep that file open in a separate window/terminal/editor during the whole debug process)

It can be hard to know what's proper and what's problematic among all that output... but if you notice something that you recognize, that's a good place to start. In my case there were many lines about nvm, the "node version manager". Disabling the nvm lines in my .zshrc file eliminates two seconds from the shell startup!

To use nvm without the performance burden, https://www.ioannispoulakas.com/2020/02/22/how-to-speed-up-shell-load-while-using-nvm/ suggests a couple possible solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.