I was trying to understand why it takes a significant amount of time (like a few seconds) to start a new zsh session.
I spent a few hrs yesterday optimizing #zsh startup time.
Thread
Key learnings:
- turn off plug-ins that you didn't use. I enabled it "just in case I would use," and I never did. For example, I got rid of rbenv (later in this thread) and removed the zsh plugin.
- revisit some unused ohmyzsh plugins (some old "custom" plug-ins took significant time to load)
I had zsh plugin for @kapeli dash that was super old (and not optimized)
I use zplug to manage my plug-ins. Excellent thing that zplug caches a lot of those. Always use ZPLUG_CACHE.
Also, zplug has `zplug load --verbose` to show what's loading.
And `zplug log` to see errors from modules.
Learned to profile using zprof.
I'm planning to understand its output more. I believe I can find some hot spots in the future.
but old good
time zsh -i -c echo
That shows effective startup time works great!
I was able to quickly understand the impact of adding individual plug-ins/configs to startup time.
- `brew --prefix` is too damn slow. Replaced with a path to the binary
- Replaced `rbenv` with chruby
- replaced `rupa/z.sh` (to jump around folders) with z.lua
Didn't explore xtrace but it looks fascinating xebia.com/blog/profiling…
Intermediate results: I was able reduce a startup the from like 3-4 sec to 1.2sec. will keep digging and report back.
Adding some links that I’ve found useful
kevin.burke.dev/kevin/profilin… by @derivativeburke
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
