TIL blog

技術ネタ, その他学んだことのアウトプット用

zplug -> zplugin に乗り換えた話 (+ exit code のbug調査)

TL;DR;

  • plugin managerを zplugから zplugin に乗り換えた. 結果, 起動時間は1/2 ~ 1/3 程度になった.
  • zpluginの簡単な紹介
  • setopt print_exit_valuezshの設定ファイルから外さないとバグる

※ドキュメントはまだそこまできちんと読んでないので, 記述に間違いがあるかも

はじめに

少し前にzshの起動が遅いのが気になってプロファイル取ったら plugin のloadで時間くってることが判明したため, plugin managerを zplugから zplugin に乗り換えた.

zpluginとは?

Zdharma Initiative のプロジェクトの一つで zplug などと同様のplugin manager

github.com

特徴として, 透過的かつ自動的に pluginをコンパイルしてくれる + 遅延読み込みの記述が容易 なため, zsh の起動が他plugin と比べて著しく速い.

意外とまだzsh のplugin managerの中ではマイナー な模様. google のsearch trendだとこんな感じだった.

  • world-wide

  • Japan

Qiitaだとzpluginの記事は7件ほど https://qiita.com/search?q=zplugin

どれだけ早くなったか

論より証拠で time benchmarkの結果を示す, およそ起動は 1/2 ~1/3 になった印象.

zplug

~
❯ for i in {1..10}; do time ( zsh -i -c exit ); done
( zsh -i -c exit; )  0.36s user 0.44s system 52% cpu 1.530 total
( zsh -i -c exit; )  0.39s user 0.44s system 65% cpu 1.258 total
( zsh -i -c exit; )  0.37s user 0.41s system 65% cpu 1.197 total
( zsh -i -c exit; )  0.36s user 0.40s system 65% cpu 1.170 total
( zsh -i -c exit; )  0.37s user 0.42s system 66% cpu 1.197 total
( zsh -i -c exit; )  0.38s user 0.41s system 65% cpu 1.198 total
( zsh -i -c exit; )  0.36s user 0.39s system 65% cpu 1.142 total
( zsh -i -c exit; )  0.37s user 0.40s system 64% cpu 1.194 total
( zsh -i -c exit; )  0.35s user 0.39s system 63% cpu 1.163 total
( zsh -i -c exit; )  0.31s user 0.33s system 64% cpu 0.992 total

zplugin

~
❯ for i in {1..10}; do time ( zsh -i -c exit ); done
( zsh -i -c exit; )  0.17s user 0.19s system 69% cpu 0.513 total
( zsh -i -c exit; )  0.18s user 0.20s system 72% cpu 0.527 total
( zsh -i -c exit; )  0.17s user 0.18s system 73% cpu 0.464 total
( zsh -i -c exit; )  0.17s user 0.19s system 72% cpu 0.489 total
( zsh -i -c exit; )  0.17s user 0.18s system 72% cpu 0.468 total
( zsh -i -c exit; )  0.17s user 0.19s system 71% cpu 0.509 total
( zsh -i -c exit; )  0.17s user 0.19s system 71% cpu 0.506 total
( zsh -i -c exit; )  0.17s user 0.18s system 73% cpu 0.477 total
( zsh -i -c exit; )  0.16s user 0.18s system 74% cpu 0.460 total
( zsh -i -c exit; )  0.17s user 0.18s system 74% cpu 0.469 total

zplg だとmodule 毎に読み込み時間を出せる, autopairは機能の割に読み込みが遅い気もする.

❯ zplg times
Plugin loading times:
0.043 sec - sindresorhus/pure
0.007 sec - sorin-ionescu/prezto
0.020 sec - zsh-users/zsh-history-substring-search
0.002 sec - junegunn/fzf-bin (command)
0.050 sec - zsh-users/zsh-autosuggestions
0.003 sec - zsh-users/zsh-completions
0.035 sec - zdharma/fast-syntax-highlighting
0.017 sec - b4b4r07/enhancd
0.003 sec - desyncr/auto-ls
0.042 sec - hlissner/zsh-autopair
0.009 sec - zdharma/zui
0.003 sec - zdharma/zplugin-crasis
0.003 sec - zdharma/history-search-multi-word
0.002 sec - zdharma/zsh-diff-so-fancy (command)
Total: 0.239 sec

踏んだbug

zplugin を入れた直後 exit code が0以外だと繰り返しexit code が表示されるbug が発生した.

以下は ctrl+c でsigint を送信した場合

Screen Recording 2019-05-11 at 11.16 AM.gif

debug でやったこと

  • zplugin を含む最小の構成でzshrc を記述 -> bug発生
  • singal 周りの記述を確認, 本家zshからコードを移植していたようなので, 本家とのdiffを確認
  • zshrcの他の設定に問題ないか binary chopでsearch
    • setopt print_exit_value が原因だった ため設定を削除
  • 結論コレと同様だった https://github.com/zdharma/zplugin/issues/45

TODO memo