Closed6
starshipが重いとき

Env
- Windows10
- PowerShell 7.4.1
❯ starship --version
starship 1.17.1
branch:master
commit_hash:
build_time:2024-01-02 18:35:11 +00:00
build_env:rustc 1.75.0 (82e1608df 2023-12-21),stable-x86_64-pc-windows-msvc

現象
特定のディレクトリに入ると、ターミナルの表示が極端に遅くなる。他のディレクトリでは発生しない。
また、Windows Powershellなどカスタムしてないシェルでも発生しない
特定のディレクトリの特徴は以下
- Gitリポジトリ
- Pythonプロジェクト
ちなみに、Powershellのカスタム内容は以下参照

原因調査
starship explain
で挙動を確認する。
参考:
正常なとき:
❯ starship explain
Here's a breakdown of your prompt:
"C:\Workspaces\hoge_dir " (<1ms) - The current working directory
"❯ " (<1ms) - A character (usually an arrow) beside where the text is entered in your terminal
遅いとき:
❯ starship explain
Here's a breakdown of your prompt:
"TOO_SLOW_DIR " (1ms) - The current working directory
"on main " (<1ms) - The active branch of the repo in your current directory
"via 🐍 v3.10.11 " (177ms) - The currently installed version of Python
"❯ " (<1ms) - A character (usually an arrow) beside where the text is entered in your terminal
Pythonのバージョンを表示するところが他に比べて時間がかかっているが、0.177秒なので問題にならないはず
他の同じような環境のパソコンで確認したところ、Pythonバージョンの表示には13msくらいだった。
今回問題になっている環境だとpyenv-win
でPythonをインストールしているので、それが問題になっているかもしれないと仮定

python環境の見直し
pyenv-winをアンインストールし、公式からインストールし直す。
参考:
pyenv
の場所を確認し、ディレクトリごと削除する
❯ where.exe pyenv
C:\Users\{USERNAME}\.pyenv\pyenv-win\bin\pyenv
C:\Users\{USERNAME}\.pyenv\pyenv-win\bin\pyenv.bat
❯ rm ~\.pyenv\
Confirm
The item at C:\Users\{USERNAME}\.pyenv\ has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
環境変数も削除
Path環境変数内
ユーザー環境変数内
以上でアンインストールできる
以下からPythonインストーラをダウンロード(今回3.10.11)
結論、133msから7msになったものの、表示の遅さは改善されず
❯ starship explain
Here's a breakdown of your prompt:
"TOO_SLOW_DIR " (1ms) - The current working directory
"on main " (<1ms) - The active branch of the repo in your current directory
"via 🐍 v3.10.11 " (7ms) - The currently installed version of Python
"❯ " (<1ms) - A character (usually an arrow) beside where the text is entered in your terminal
# ↑の表示は早いが、ここからカーソルが表示されるまでが遅い!
❯
そもそもstarship explain
での表示は早いがそこからカーソルが表示されるまでが遅く、別の要因である可能性が高い 検討もつかないが…

メモ:
starshipを無効化しても遅かった。プロファイルを確認するとstarshipのあとにImport-Module posh-git
をしており、これをコメントアウトすると速度がもとに戻った。

$PROFILEに以下記載することで改善された。
$GitPromptSettings.EnableFileStatus = $false # 簡易ステータス非表示
このスクラップは2024/04/25にクローズされました