zsh の check-for-changes をやめて check-for-staged-changes を使う

zsh のプロンプトに現在いる git リポジトリの状態を表示させたいと思って、今までいくつかの設定を .zshrc に書いていたのだけど、ある巨大な git リポジトリを clone してきたディレクトリ内に限り、 cd コマンドを打ったり、そもそも何もコマンドを打たずに Enter キーを押しただけでも、結果が返ってくるまでにそこそこの頻度で 1 分ぐらいかかってマシンのファンが凄い勢いで回り始めるという現象が起きるようになってしまった。

それで今まで騙し騙し使っていたのを今日ちょっとさすがに原因を調べようと思っていろいろ見ていたところ「 check-for-changes は重い」というような記述を見つけた。 そこで man zshcontrib を読んでみると

check-for-changes

   If enabled, this style causes the %c and %u format escapes to show when the working directory has uncommitted changes. The strings displayed by these escapes can be controlled via  the
   stagedstr and unstagedstr styles. The only backends that currently support this option are git, hg, and bzr (the latter two only support unstaged).

   For this style to be evaluated with the hg backend, the get-revision style needs to be set and the use-simple style needs to be unset. The latter is the default; the former is not.

   With the bzr backend, lightweight checkouts only honor this style if the use-server style is set.

   Note,  the  actions  taken  if  this  style is enabled are potentially expensive (read: they may be slow, depending on how big the current repository is).  Therefore, it is disabled by
   default.

特に最後の一文の Note に

the actions taken if this style is enabled are potentially expensive (read: they may be slow, depending on how big the current repository is). Therefore, it is disabled by default.

と明確に書かれていた。

check-for-changes を無効にすることも選択肢の一つとしてはあるのだろうけど、やっぱり未 commit の変更が成されたファイルが無いか、そういう dirty な状態でないかは表示させたいよな…と思ったところ、すぐ下に

check-for-staged-changes

   This style is like check-for-changes, but it never checks the worktree files, only the metadata in the .${vcs} dir.  Therefore, this style initializes only the %c escape (with  staged‐
   str) but not the %u escape.  This style is faster than check-for-changes.

   In the git backend, this style checks for changes in the index.  Other backends do not currently implement this style.

   This style is disabled by default.

という値の説明があった。つまり check-for-changes では staging エリアだけでなく作業ディレクトリ内に変更があるかどうかもチェックするが、 check-for-staged-changes なら staging エリアに変更されたファイルがあるかどうかだけをチェックするので check-for-changes よりも速い、ということだ。

そこで

zstyle ':vcs_info:git:*' check-for-changes true

と設定していたのを

zstyle ':vcs_info:git:*' check-for-staged-changes true

と書き換えた。すると結果が返ってくるまでに 10 秒ぐらいかかる時もあるものの、待ち時間はずいぶん改善された。

今までプロンプトに表示させていた情報が 1 つ落ちるのでまだちょっと心もとないが、まあ現実的に妥当な落とし所ではあるかな…

もう少しこのまま使って様子を見ようと思う。