1、启动耗时分析

正常启动耗时:
time zsh -i -c exit
zsh -i -c exit 3.26s user 8.73s system 93% cpu 12.836 total

简洁模式:
time zsh --no-rcs -i -c exit
zsh --no-rcs -i -c exit 0.00s user 0.01s system 70% cpu 0.010 total

2、分析具体哪些因素导致变慢

(1)vim .zshrc

开启可以用来分析zsh启动耗时

zmodload zsh/zprof

(2)执行命令

~ zsh
~ zprof
num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    2         251.69   125.84   62.08%     79.77    39.89   19.68%  compinit
 2)    1          76.87    76.87   18.96%     76.87    76.87   18.96%  compdump
 3)  810          73.68     0.09   18.17%     73.68     0.09   18.17%  compdef
 4)   25          66.65     2.67   16.44%     58.12     2.32   14.34%  _omz_source
 5)    4          21.74     5.44    5.36%     21.74     5.44    5.36%  compaudit
 6)   12          13.76     1.15    3.40%     13.76     1.15    3.40%  _zsh_highlight_main__type
 7)    5           9.99     2.00    2.46%      8.65     1.73    2.13%  _zsh_autosuggest_async_request
 8)    3           8.24     2.75    2.03%      8.24     2.75    2.03%  __sdkman_export_candidate_home
 9)    3           7.82     2.61    1.93%      7.82     2.61    1.93%  __sdkman_prepend_candidate_to_path
10)    7          28.21     4.03    6.96%      5.82     0.83    1.44%  _zsh_highlight
11)  193           6.35     0.03    1.57%      5.33     0.03    1.32%  _zsh_autosuggest_bind_widget
12)    1           3.68     3.68    0.91%      3.64     3.64    0.90%  _zsh_highlight_load_highlighters
13)    5          21.45     4.29    5.29%      3.24     0.65    0.80%  _zsh_autosuggest_bound_1_self-insert
14)    6          19.73     3.29    4.87%      3.09     0.52    0.76%  _zsh_highlight_main_highlighter_highlight_list
15)    1           9.36     9.36    2.31%      3.01     3.01    0.74%  _zsh_autosuggest_bind_widgets
16)    7           4.93     0.70    1.22%      2.68     0.38    0.66%  _zsh_autosuggest_invoke_original_widget
17)    1           2.62     2.62    0.65%      2.62     2.62    0.65%  (anon) [/Users/zhangsj190/.oh-my-zsh/tools/check_for_upgrade.sh:157]
18)    6           2.16     0.36    0.53%      2.16     0.36    0.53%  url-quote-magic
19)   15           1.97     0.13    0.49%      1.97     0.13    0.49%  is-at-least
20)    4           1.84     0.46    0.45%      1.76     0.44    0.44%  _zsh_highlight_main_highlighter_check_path
21)    6          16.82     2.80    4.15%      1.74     0.29    0.43%  _zsh_autosuggest_modify
22)    1           1.52     1.52    0.37%      1.52     1.52    0.37%  omz_termsupport_cwd
23)    1           4.10     4.10    1.01%      1.49     1.49    0.37%  handle_update
24)    6          22.08     3.68    5.45%      1.42     0.24    0.35%  _zsh_highlight_highlighter_main_paint
25)    1           1.39     1.39    0.34%      1.39     1.39    0.34%  test-ls-args
26)    6          28.33     4.72    6.99%      1.18     0.20    0.29%  azhw:zle-line-pre-redraw
27)    6          18.51     3.09    4.57%      1.13     0.19    0.28%  _zsh_autosuggest_widget_modify
28)  193           1.02     0.01    0.25%      1.02     0.01    0.25%  _zsh_autosuggest_incr_bind_count
29)    5           1.51     0.30    0.37%      0.89     0.18    0.22%  _zsh_autosuggest_async_response
30)    1           0.72     0.72    0.18%      0.72     0.72    0.18%  _zsh_highlight__function_callable_p
31)    6           0.63     0.11    0.16%      0.63     0.11    0.16%  _zsh_highlight_main_calculate_fallback
32)    1           0.57     0.57    0.14%      0.57     0.57    0.14%  zrecompile
33)    3           0.53     0.18    0.13%      0.51     0.17    0.13%  add-zle-hook-widget

(3)优化compinit、compdump、compdef
在.zshrc最后添加以下

# 以下用来优化zsh启动耗时
if [[ -n $(print ~/.zcompdump(Nmh+24)) ]] {
  # Regenerate completions because the dump file hasn't been modified within the last 24 hours
  compinit
} else {
  # Reuse the existing completions file
  compinit -C
}

(4)优化_omz_source

3、发现一个巨大的问题,pyenv一直在echo写新的路径到末尾,删掉后就ok了,只保留这4条即可。这时候source就飞快了,打开新的标签也飞快了。和插件其实关系不大。。。

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"



登陆发表评论