Zsh is already the default shell of macOS Catalina. As we configure more and more plugins for zsh, the startup speed of zsh becomes slower and slower. This article will introduce how to measure and optimize the startup speed of Zsh.
We can use the time command to view the startup time of Zsh in a coarse-grained manner
1 2 3 4
$ time zsh -i -c exit Saving session...completed. Deleting expired sessions... 60 completed. zsh -i -c exit 0.21s user 0.21s system 92% cpu 0.453 total
1 2 3
$ time zsh -i -c exit Saving session...completed. zsh -i -c exit 0.13s user 0.04s system 93% cpu 0.179 total
Use zprof to see the time-consuming of Zsh loading. Edit the ~/.zshrc file and add the following code at the beginning.
Start zsh again, and enter zprof , you can see that it lists specific time-consuming items.