It seems like my shell is taking way too long to start up. Is there any way to profile it so I can figure out what\'s slowing it down so much?
Zsh has a profiling module. At the beginning of ~/.zshrc or ~/.zshenv add it like:
# Uncomment to use the profiling module
# zmodload zsh/zprof
Uncomment it, start a new interactive shell then run the command zprof. You will get a detailed list of items you can review to better understand where your performance bottlenecks are:
num calls time self name
-----------------------------------------------------------------------------------
1) 1 7.29 7.29 19.60% 7.29 7.29 19.60% _p9k_init_ssh
2) 2 6.72 3.36 18.06% 6.63 3.31 17.81% gitstatus_start_impl
3) 1 4.00 4.00 10.75% 4.00 4.00 10.75% _p9k_must_init
4) 3 19.28 6.43 51.80% 3.82 1.27 10.28% (anon)
5) 1 1.63 1.63 4.37% 1.63 1.63 4.37% _p9k_restore_state_impl
6) 1 16.92 16.92 45.46% 1.61 1.61 4.32% _p9k_precmd_impl
7) 1 7.13 7.13 19.16% 0.87 0.87 2.33% _p9k_set_prompt
8) 22 6.26 0.28 16.83% 0.84 0.04 2.27% _p9k_build_segment
9) 17 0.82 0.05 2.19% 0.82 0.05 2.19% _p9k_param
10) 6 2.24 0.37 6.02% 0.74 0.12 1.98% _p9k_left_prompt_segment
11) 5 0.59 0.12 1.60% 0.59 0.12 1.60% add-zsh-hook
12) 1 3.05 3.05 8.20% 0.58 0.58 1.56% prompt_dir
And here's a one-liner from speeding up zsh you'll appreciate if start time feels sporadic:
for i in $(seq 1 10); do /usr/bin/time zsh -i -c exit; done
Run that job and you should see output like:
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
0.05 real 0.02 user 0.02 sys
Profit.