- Cold start:
412ms
- Warm start:
195ms
Initialization of the completion system (compinit
/compaudit
/compdef
) appears to be the slowest part of shell startup. As shown by this test, zsh automatically handles caching for this which cuts startup time in half for subsequent shells.
-
Add
zmodload zsh/zprof
to the start of~/.zshrc
andzprof
to the end of the file. -
Set TIMEFMT to show miliseconds:
export TIMEFMT="%J %mU user %mS system %P cpu %mE total"
# Clear caches
rm -rf ~/.cache/oh-my-posh ~/.zcompcache ~/.zcompdump
# Run cold start test
time zsh -i -c exit
num calls time self name
-----------------------------------------------------------------------------------
1) 1 240.72 240.72 97.51% 95.54 95.54 38.70% compinit
2) 1 65.80 65.80 26.66% 65.80 65.80 26.66% compdump
3) 797 64.27 0.08 26.04% 64.27 0.08 26.04% compdef
4) 2 15.22 7.61 6.16% 15.22 7.61 6.16% compaudit
5) 1 3.47 3.47 1.41% 3.43 3.43 1.39% _zsh_highlight_load_highlighters
6) 1 0.75 0.75 0.30% 0.74 0.74 0.30% _zsh_highlight__function_callable_p
7) 1 0.53 0.53 0.22% 0.49 0.49 0.20% enable_poshtooltips
8) 5 0.32 0.06 0.13% 0.32 0.06 0.13% add-zsh-hook
9) 3 0.33 0.11 0.13% 0.31 0.10 0.12% add-zle-hook-widget
10) 3 0.27 0.09 0.11% 0.27 0.09 0.11% is-at-least
11) 1 0.26 0.26 0.10% 0.26 0.26 0.10% _omp_cleanup
12) 1 0.11 0.11 0.04% 0.11 0.11 0.04% (anon) [/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
13) 1 0.04 0.04 0.02% 0.04 0.04 0.02% _omp_create_widget
14) 1 0.03 0.03 0.01% 0.03 0.03 0.01% (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28]
15) 1 0.02 0.02 0.01% 0.02 0.02 0.01% nvm_process_parameters
16) 1 0.01 0.01 0.00% 0.01 0.01 0.00% nvm_auto
17) 1 0.01 0.01 0.00% 0.01 0.01 0.00% nvm_is_zsh
18) 1 0.01 0.01 0.00% 0.01 0.01 0.00% _zsh_highlight__is_function_p
19) 1 0.00 0.00 0.00% 0.00 0.00 0.00% _zsh_highlight_bind_widgets
-----------------------------------------------------------------------------------
1) 1 240.72 240.72 97.51% 95.54 95.54 38.70% compinit
1/2 15.22 15.22 6.16% 0.13 0.13 compaudit [4]
795/797 64.17 0.08 25.99% 64.17 0.08 compdef [3]
1/1 65.80 65.80 26.66% 65.80 65.80 compdump [2]
-----------------------------------------------------------------------------------
1/1 65.80 65.80 26.66% 65.80 65.80 compinit [1]
2) 1 65.80 65.80 26.66% 65.80 65.80 26.66% compdump
-----------------------------------------------------------------------------------
795/797 64.17 0.08 25.99% 64.17 0.08 compinit [1]
3) 797 64.27 0.08 26.04% 64.27 0.08 26.04% compdef
-----------------------------------------------------------------------------------
1/2 15.22 15.22 6.16% 0.13 0.13 compinit [1]
1/2 15.08 15.08 6.11% 15.08 15.08 compaudit [4]
4) 2 15.22 7.61 6.16% 15.22 7.61 6.16% compaudit
1/2 15.08 15.08 6.11% 15.08 15.08 compaudit [4]
-----------------------------------------------------------------------------------
5) 1 3.47 3.47 1.41% 3.43 3.43 1.39% _zsh_highlight_load_highlighters
1/5 0.04 0.04 0.02% 0.04 0.04 add-zsh-hook [8]
-----------------------------------------------------------------------------------
6) 1 0.75 0.75 0.30% 0.74 0.74 0.30% _zsh_highlight__function_callable_p
1/1 0.01 0.01 0.00% 0.01 0.01 _zsh_highlight__is_function_p [18]
-----------------------------------------------------------------------------------
7) 1 0.53 0.53 0.22% 0.49 0.49 0.20% enable_poshtooltips
1/1 0.04 0.04 0.02% 0.04 0.04 _omp_create_widget [13]
-----------------------------------------------------------------------------------
1/3 0.07 0.07 0.03% 0.07 0.07 add-zle-hook-widget [9]
9) 3 0.33 0.11 0.13% 0.31 0.10 0.12% add-zle-hook-widget
1/1 0.03 0.03 0.01% 0.03 0.03 (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28] [14]
1/3 0.07 0.07 0.03% 0.07 0.07 add-zle-hook-widget [9]
-----------------------------------------------------------------------------------
1/5 0.04 0.04 0.02% 0.04 0.04 _zsh_highlight_load_highlighters [5]
8) 5 0.32 0.06 0.13% 0.32 0.06 0.13% add-zsh-hook
-----------------------------------------------------------------------------------
10) 3 0.27 0.09 0.11% 0.27 0.09 0.11% is-at-least
-----------------------------------------------------------------------------------
11) 1 0.26 0.26 0.10% 0.26 0.26 0.10% _omp_cleanup
-----------------------------------------------------------------------------------
12) 1 0.11 0.11 0.04% 0.11 0.11 0.04% (anon) [/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
-----------------------------------------------------------------------------------
1/1 0.04 0.04 0.02% 0.04 0.04 enable_poshtooltips [7]
13) 1 0.04 0.04 0.02% 0.04 0.04 0.02% _omp_create_widget
-----------------------------------------------------------------------------------
1/1 0.03 0.03 0.01% 0.03 0.03 add-zle-hook-widget [9]
14) 1 0.03 0.03 0.01% 0.03 0.03 0.01% (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28]
-----------------------------------------------------------------------------------
15) 1 0.02 0.02 0.01% 0.02 0.02 0.01% nvm_process_parameters
1/1 0.01 0.01 0.00% 0.01 0.01 nvm_auto [16]
-----------------------------------------------------------------------------------
1/1 0.01 0.01 0.00% 0.01 0.01 nvm_process_parameters [15]
16) 1 0.01 0.01 0.00% 0.01 0.01 0.00% nvm_auto
-----------------------------------------------------------------------------------
17) 1 0.01 0.01 0.00% 0.01 0.01 0.00% nvm_is_zsh
-----------------------------------------------------------------------------------
1/1 0.01 0.01 0.00% 0.01 0.01 _zsh_highlight__function_callable_p [6]
18) 1 0.01 0.01 0.00% 0.01 0.01 0.00% _zsh_highlight__is_function_p
-----------------------------------------------------------------------------------
19) 1 0.00 0.00 0.00% 0.00 0.00 0.00% _zsh_highlight_bind_widgets
zsh -i -c exit 235ms user 136ms system 90% cpu 412ms total
Simply run the test again after the cold start.
time zsh -i -c exit
num calls time self name
-----------------------------------------------------------------------------------
1) 2 15.07 7.53 48.10% 15.07 7.53 48.10% compaudit
2) 1 25.10 25.10 80.12% 10.03 10.03 32.02% compinit
3) 1 3.46 3.46 11.06% 3.42 3.42 10.92% _zsh_highlight_load_highlighters
4) 1 0.82 0.82 2.63% 0.82 0.82 2.61% _zsh_highlight__function_callable_p
5) 1 0.55 0.55 1.77% 0.51 0.51 1.64% enable_poshtooltips
6) 5 0.32 0.06 1.03% 0.32 0.06 1.03% add-zsh-hook
7) 3 0.34 0.11 1.09% 0.32 0.11 1.01% add-zle-hook-widget
8) 3 0.26 0.09 0.82% 0.26 0.09 0.82% is-at-least
9) 1 0.26 0.26 0.82% 0.26 0.26 0.82% _omp_cleanup
10) 2 0.12 0.06 0.38% 0.12 0.06 0.38% compdef
11) 1 0.11 0.11 0.34% 0.11 0.11 0.34% (anon) [/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
12) 1 0.04 0.04 0.13% 0.04 0.04 0.13% _omp_create_widget
13) 1 0.02 0.02 0.08% 0.02 0.02 0.08% (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28]
14) 1 0.02 0.02 0.06% 0.02 0.02 0.05% nvm_process_parameters
15) 1 0.01 0.01 0.02% 0.01 0.01 0.02% _zsh_highlight__is_function_p
16) 1 0.00 0.00 0.02% 0.00 0.00 0.02% nvm_auto
17) 1 0.00 0.00 0.01% 0.00 0.00 0.01% nvm_is_zsh
18) 1 0.00 0.00 0.00% 0.00 0.00 0.00% _zsh_highlight_bind_widgets
-----------------------------------------------------------------------------------
2) 1 25.10 25.10 80.12% 10.03 10.03 32.02% compinit
1/2 15.07 15.07 48.10% 0.13 0.13 compaudit [1]
-----------------------------------------------------------------------------------
1/2 15.07 15.07 48.10% 0.13 0.13 compinit [2]
1/2 14.94 14.94 47.69% 14.94 14.94 compaudit [1]
1) 2 15.07 7.53 48.10% 15.07 7.53 48.10% compaudit
1/2 14.94 14.94 47.69% 14.94 14.94 compaudit [1]
-----------------------------------------------------------------------------------
3) 1 3.46 3.46 11.06% 3.42 3.42 10.92% _zsh_highlight_load_highlighters
1/5 0.04 0.04 0.14% 0.04 0.04 add-zsh-hook [6]
-----------------------------------------------------------------------------------
4) 1 0.82 0.82 2.63% 0.82 0.82 2.61% _zsh_highlight__function_callable_p
1/1 0.01 0.01 0.02% 0.01 0.01 _zsh_highlight__is_function_p [15]
-----------------------------------------------------------------------------------
5) 1 0.55 0.55 1.77% 0.51 0.51 1.64% enable_poshtooltips
1/1 0.04 0.04 0.13% 0.04 0.04 _omp_create_widget [12]
-----------------------------------------------------------------------------------
1/3 0.08 0.08 0.24% 0.08 0.08 add-zle-hook-widget [7]
7) 3 0.34 0.11 1.09% 0.32 0.11 1.01% add-zle-hook-widget
1/1 0.02 0.02 0.08% 0.02 0.02 (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28] [13]
1/3 0.08 0.08 0.24% 0.08 0.08 add-zle-hook-widget [7]
-----------------------------------------------------------------------------------
1/5 0.04 0.04 0.14% 0.04 0.04 _zsh_highlight_load_highlighters [3]
6) 5 0.32 0.06 1.03% 0.32 0.06 1.03% add-zsh-hook
-----------------------------------------------------------------------------------
8) 3 0.26 0.09 0.82% 0.26 0.09 0.82% is-at-least
-----------------------------------------------------------------------------------
9) 1 0.26 0.26 0.82% 0.26 0.26 0.82% _omp_cleanup
-----------------------------------------------------------------------------------
10) 2 0.12 0.06 0.38% 0.12 0.06 0.38% compdef
-----------------------------------------------------------------------------------
11) 1 0.11 0.11 0.34% 0.11 0.11 0.34% (anon) [/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh:460]
-----------------------------------------------------------------------------------
1/1 0.04 0.04 0.13% 0.04 0.04 enable_poshtooltips [5]
12) 1 0.04 0.04 0.13% 0.04 0.04 0.13% _omp_create_widget
-----------------------------------------------------------------------------------
1/1 0.02 0.02 0.08% 0.02 0.02 add-zle-hook-widget [7]
13) 1 0.02 0.02 0.08% 0.02 0.02 0.08% (anon) [/usr/share/zsh/5.9/functions/add-zle-hook-widget:28]
-----------------------------------------------------------------------------------
14) 1 0.02 0.02 0.06% 0.02 0.02 0.05% nvm_process_parameters
1/1 0.00 0.00 0.02% 0.00 0.00 nvm_auto [16]
-----------------------------------------------------------------------------------
1/1 0.01 0.01 0.02% 0.01 0.01 _zsh_highlight__function_callable_p [4]
15) 1 0.01 0.01 0.02% 0.01 0.01 0.02% _zsh_highlight__is_function_p
-----------------------------------------------------------------------------------
1/1 0.00 0.00 0.02% 0.00 0.00 nvm_process_parameters [14]
16) 1 0.00 0.00 0.02% 0.00 0.00 0.02% nvm_auto
-----------------------------------------------------------------------------------
17) 1 0.00 0.00 0.01% 0.00 0.00 0.01% nvm_is_zsh
-----------------------------------------------------------------------------------
18) 1 0.00 0.00 0.00% 0.00 0.00 0.00% _zsh_highlight_bind_widgets
zsh -i -c exit 131ms user 41ms system 88% cpu 195ms total