lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm
MIT License
2.24k stars 113 forks source link

nvm load on session start takes ~30 seconds, lazy load not working #86

Open MyNameIsOka opened 2 years ago

MyNameIsOka commented 2 years ago

Hi everybody,

I have had this problem for some time now and didn't find a solution, so I hope you guys can help me out. When I use zsh-nvm without lazy load, the session start takes insanely long (~30 seconds). That startup is only that slow when I open Terminal the first time after a restart of the machine. When I use lazy loading, .nvmrc files are ignored until I manually enter something like nvm -v and then cd in the corresponding folder.

EDIT: I just saw that you wrote about this in the README: https://github.com/lukechilds/zsh-nvm#auto-use

I tried to fix it according to issue #28 but adding PATH before zsh-nvm didn't change anything.

add-zsh-hook chpwd _zsh_nvm_auto_use && echo yep || echo nope

gives me yep

I don't know what I should look for or what the culprit could be. I hope you guys can give me some tips on where to look!

mattbontrager commented 2 years ago

Looking through the various issues, several of them identify what I am experiencing but I think this one is probably the best place for me to follow on.

Just to be sure it wasn't a broader problem, I did this. Still, no luck.

To validate the issue, I tested the plugin loading times using the "A Note on Profiling with zsh/zprof" section of this article. The results I got were pretty surprising.

This first test was what I was initially dealing with:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1       16982.97 16982.97   65.03%  16982.71 16982.71   65.03%  _zsh_nvm_auto_use
 2)    2        6257.87  3128.93   23.96%   3328.52  1664.26   12.75%  nvm
 3)    1        2835.52  2835.52   10.86%   2772.00  2772.00   10.61%  nvm_ensure_version_installed
 4)    1        7862.78  7862.78   30.11%   1604.91  1604.91    6.15%  nvm_auto
 5)    1        1091.19  1091.19    4.18%   1090.75  1090.75    4.18%  _zsh_nvm_lazy_load
 6)    1          93.17    93.17    0.36%     92.95    92.95    0.36%  nvm_die_on_prefix
 7)    3         100.92    33.64    0.39%     79.26    26.42    0.30%  compinit
 8)    1          63.52    63.52    0.24%     63.52    63.52    0.24%  nvm_is_version_installed
 9)  192          25.70     0.13    0.10%     21.69     0.11    0.08%  _zsh_autosuggest_bind_widget
10)    2          21.66    10.83    0.08%     21.66    10.83    0.08%  compaudi
...

Then, I set NVM_AUTO_USE=false. This was the improvement I saw:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    2        6005.54  3002.77   73.61%   3289.87  1644.93   40.32%  nvm
 2)    1        2622.10  2622.10   32.14%   1932.04  1932.04   23.68%  nvm_ensure_version_installed
 3)    1        1130.55  1130.55   13.86%   1129.79  1129.79   13.85%  _zsh_nvm_lazy_load
 4)    1        6828.53  6828.53   83.69%    822.99   822.99   10.09%  nvm_auto
 5)    1         690.06   690.06    8.46%    690.06   690.06    8.46%  nvm_is_version_installed
 6)    1          92.38    92.38    1.13%     92.11    92.11    1.13%  nvm_die_on_prefix
 7)    3         121.23    40.41    1.49%     84.85    28.28    1.04%  compinit
 8)    2          36.37    18.19    0.45%     36.37    18.19    0.45%  compaudit
...

Finally, I deleted zsh-nvm from the list of plugins in my .zshrc and it became obvious that zsh-nvm is what is killing my load times:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    2        1796.27   898.13   55.22%   1035.22   517.61   31.82%  nvm
 2)    3        1153.82   384.61   35.47%    765.91   255.30   23.54%  compinit
 3)    1         690.32   690.32   21.22%    634.07   634.07   19.49%  nvm_ensure_version_installed
 4)    1         244.02   244.02    7.50%    244.02   244.02    7.50%  compdump
 5)    1        2016.84  2016.84   62.00%    220.58   220.58    6.78%  nvm_auto
 6)  923         123.67     0.13    3.80%    123.67     0.13    3.80%  compdef
 7)    1          70.17    70.17    2.16%     69.96    69.96    2.15%  nvm_die_on_prefix
 8)    1          56.25    56.25    1.73%     56.25    56.25    1.73%  nvm_is_version_installed
 9)  192          32.25     0.17    0.99%     27.56     0.14    0.85%  _zsh_autosuggest_bind_widget
10)    2          21.48    10.74    0.66%     21.48    10.74    0.66%  compaudit

P.s. Lazy loading it did nothing to improve load times.