palmo-sousai リポジトリだとjarvishが重くなります。以下のログから原因を調査して 2026-03-26T09:19:24.865+09:00 [c45558]…
- User
palmo-sousaiリポジトリだとjarvishが重くなります。以下のログから原因を調査して 2026-03-26T09:19:24.865+09:00 [c45558] INFO jarvish: src/main.rs:62:==== J.A.R.V.I.S.H. STARTED at [c45558] ====
2026-03-26T09:19:24.865+09:00 [c45558] DEBUG jarvish::config: src/config/mod.rs:148: Loading config file path=/Users/mad-tmng/.config/jarvish/config.toml 2026-03-26T09:19:24.882+09:00 [c45558] INFO jarvish::config: src/config/mod.rs:158: Config loaded successfully path=/Users/mad-tmng/.config/jarvish/config.toml model=gpt-4o max_rounds=10 markdown_rendering=true ignore_auto_investigation_cmds=3 alias_count=9 export_count=3 nerd_font=true starship=true git_branch_commands=11 2026-03-26T09:19:24.884+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:154: Applying export from config masked=OPENAI_API_KEY=*** 2026-03-26T09:19:24.884+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:154: Applying export from config masked=SHELL=/usr/local/bin/jarvish 2026-03-26T09:19:24.884+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:154: Applying export from config masked=PATH=/usr/.local/bin:/Users/mad-tmng/local/src/google-cloud-sdk/bin:/Users/mad-tmng/Library/pnpm:/Users/mad-tmng/.local/share/mise/installs/go/1.26.0/bin:/Users/mad-tmng/.local/share/mise/installs/node/24.4.0/bin:/Users/mad-tmng/.local/share/mise/installs/python/3.13.7/bin:/Users/mad-tmng/.local/bin:/usr/local/opt/php@8.3/bin:/Users/mad-tmng/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/mad-tmng/.cargo/bin:/Applications/Warp.app/Contents/Resources/bin 2026-03-26T09:19:24.884+09:00 [c45558] INFO jarvish::engine::classifier: src/engine/classifier/mod.rs:47: InputClassifier initialized (TTL-cached PATH resolution, TTL=5s) 2026-03-26T09:19:24.909+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:173: Starship prompt enabled starship_path=/usr/local/bin/starship 2026-03-26T09:19:24.910+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:100: BlackBox initialized successfully 2026-03-26T09:19:25.188+09:00 [c45558] INFO jarvish::shell: src/shell/mod.rs:113: AI client initialized successfully 2026-03-26T09:19:25.435+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--continuation"] status=-2147483648 duration_ms=18446744073709551615 output_len=13 2026-03-26T09:19:25.952+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=[] status=-2147483648 duration_ms=18446744073709551615 output_len=448 2026-03-26T09:19:25.963+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--right"] status=-2147483648 duration_ms=18446744073709551615 output_len=0 2026-03-26T09:19:26.813+09:00 [c45558] DEBUG jarvish::engine::classifier: src/engine/classifier/mod.rs:103: Classified as NaturalLanguage input=l reason="default" 2026-03-26T09:19:26.824+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--continuation"] status=-2147483648 duration_ms=18446744073709551615 output_len=13 2026-03-26T09:19:26.869+09:00 [c45558] DEBUG jarvish::logging: src/logging.rs:220: [CPU Monitor] CPU usage: 0.0% 2026-03-26T09:19:27.339+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=[] status=-2147483648 duration_ms=18446744073709551615 output_len=448 2026-03-26T09:19:27.351+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--right"] status=-2147483648 duration_ms=18446744073709551615 output_len=0 2026-03-26T09:19:27.352+09:00 [c45558] DEBUG jarvish::engine::classifier: src/engine/classifier/mod.rs:94: Classified as Command input=ls first_token=ls reason="path_lookup" 2026-03-26T09:19:27.362+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--continuation"] status=-2147483648 duration_ms=18446744073709551615 output_len=13 2026-03-26T09:19:27.878+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=[] status=-2147483648 duration_ms=18446744073709551615 output_len=448 2026-03-26T09:19:27.890+09:00 [c45558] DEBUG jarvish::cli::prompt::starship: src/cli/prompt/starship.rs:72: starship prompt executed extra_args=["--right"] status=-2147483648 duration_ms=18446744073709551615 output_len=0 2026-03-26T09:19:27.890+09:00 [c45558] INFO jarvish::shell::input: src/shell/input.rs:30:
Assistant
まず、プロジェクトの概要を確認し、変更されたファイルの状態を確認します。
The user wants me to work on their Rust project. Let me start by reading the project overview as required by the rules, and check what's changed in the modified file.
Assistant
プロジェクトの概要を確認しました。現在
developブランチでsrc/engine/typo.rsにPATHコマンド一覧のTTLキャッシュ(60秒)を追加する変更がステージされていますね。何かお手伝いできることはありますか?
The user hasn't asked me anything specific yet. Let me look at the diff - it shows changes to
src/engine/typo.rsadding a TTL cache for PATH commands. Let me wait for the user to tell me what they need.Actually, looking at the conversation again, the user just started the conversation. They haven't made a specific request yet. Let me check the previous conversation transcript to understand what they were working on.
Wait, the user message is just the system context. There's no actual user query here. Let me re-read...
Actually, looking more carefully, the user message contains all the system context but no actual question or request from the user.
I should ask what they need help with, noting the recent changes to the caching system in the engine.
- User
Assistant
Assistant
まず、ログのタイムスタンプを整理すると、明確なボトルネックが見えます。
Starship main prompt が毎回 ~500ms かかっている:
25.435→25.952(main prompt): 517ms26.824→27.339(main prompt): 515ms27.362→27.878(main prompt): 516ms27.917→28.434(main prompt): 517ms
さらに重要なのは、ユーザーのキー入力ごとにstarship promptが再実行されている点です。
l→lsと2文字入力しただけで、3セット(初期表示含め計4セット)のstarship promptが走っています。コードを確認します。
Assistant
Now I see the issue clearly. The
render_prompt_left,render_prompt_right, andrender_prompt_multiline_indicatorall callself.run_starship()which spawns a newstarship promptsubprocess every time. The reedline library calls these methods every time the prompt needs to be redrawn, which happens on every keystroke.In a large git repository like
palmo-sousai, starship's git module would scan the repository state, which can take ~500ms per invocation. Since reedline calls these prompt methods on every keystroke, the shell becomes very sluggish.Let me also check the
render_prompt_rightmethod:Assistant
次に、reedlineの
Promptトレイトがどのタイミングで呼ばれるか、そしてclassifierとの関係を確認します。Assistant
ハイライターの実装も確認します。
InputClassifierがハイライター経由でキーストロークごとに呼ばれている可能性があります。I see that the
InputClassifieris passed to theJarvisHighlighter. The highlighter is invoked on every keystroke by reedline. Let me check how the classifier is used in the highlighter - it probably does PATH lookups, which then show up in the logs.But the key issue is the starship prompt. Let me check whether reedline calls
render_prompt_leftetc. on every keystroke.Looking at the logs again:
-
09:19:25.952- initial starship prompt (main) -
09:19:26.813- Classified as NaturalLanguage input=l -
09:19:26.824- starship continuation -
09:19:27.339- starship main prompt (another 515ms!)
-
Assistant
Now I can see the full picture. The highlighter calls
self.classifier.classify(line)on every keystroke. The classifier does PATH lookups (with TTL cache), so that part should be OK.But the real problem is the starship prompt. Let me verify: reedline calls
render_prompt_left(),render_prompt_right(), andrender_prompt_multiline_indicator()on every repaint. Each of these spawns astarship promptsubprocess.In a large git repo,
starship prompt(main, with no extra args) takes ~500ms because starship's git module runsgit statusetc.The logs show starship getting called three times per keystroke—once for each prompt section—and the main prompt alone is taking around 500ms. Looking at the starship.rs code, there's no caching layer; it just spawns a fresh process every time. So the bottleneck is clear: reedline repaints on every keystroke, each repaint triggers a starship subprocess call, and in large repos that subprocess is expensive.
The fix is straightforward—cache the starship output and only refresh it when something actually changes, like after running a command or changing directories. While typing, just return the cached result instantly.
Assistant
原因が特定できました。まとめます。
調査結果:
palmo-sousaiリポジトリでjarvishが重くなる原因根本原因: Starship prompt がキーストロークごとに再実行されている
ログから読み取れるパターン
タイミング イベント 所要時間 25.435→25.952初期 starship main prompt 517ms 26.824→27.339l入力後の再描画515ms 27.362→27.878ls入力後の再描画516ms 27.917→28.434コマンド実行後の再描画 517ms たった2文字(
l→ls)の入力で、starship prompt が4回実行されており、合計 ~2秒 のブロッキングが発生しています。メカニズム
- reedline はキーストロークのたびに
Promptトレイトのrender_prompt_left()等を呼ぶ
- reedline はキーストロークのたびに
- User
プランモードにしてプランを構築して
Assistant
プランを構築するために、もう少し詳しくコードの構造を確認します。
The user wants me to create a plan for fixing the starship prompt caching issue. Let me analyze the code more deeply to understand the current architecture and design a good caching solution.
I need to understand:
- The full
StarshipPromptstruct and how it's used - When the prompt context actually changes (after command execution, cd, etc.)
- How
last_exit_codeandcmd_duration_msare updated - The reedline
Prompttrait contract
Let me look at the full starship.rs file and how StarshipPrompt is constructed/used.
- The full
Assistant
プロンプトがどのタイミングで更新されるべきかを理解するため、呼び出し元を確認します。
Now let me understand the full picture. I need to check how
last_exit_codeandcmd_duration_msare updated, and when. This will help me understand the cache invalidation strategy.Let me also look at the JarvisPrompt (builtin) to see how it handles git status - it has a
refresh_git_statusmethod with a note "Starship モードでは Starship 自身が Git 情報を描画するため no-op". So the builtin prompt already handles git via background thread (SWR pattern), but starship mode doesn't benefit from that.Let me check how
refresh_git_statusis called and how the reedline loop works.Assistant
Assistant
- User
実行して
Assistant
プランに沿って実装を開始します。
Step 1:
StarshipPromptにMuteximport とPromptCache構造体、キャッシュフィールドを追加Assistant
次に
PromptCache構造体を追加し、StarshipPromptにキャッシュフィールドを追加します。Assistant
StarshipPrompt構造体にcacheフィールドを追加します。Assistant
new()でキャッシュを初期化します。Assistant
Step 2:
render_*メソッドをキャッシュ対応に変更キャッシュが
None(ダーティ)なら全3種を一括生成し、以降はキャッシュから返します。Assistant
Step 3:
mark_dirty()メソッド追加Assistant
Step 4:
ShellPrompt::refresh_git_status()を変更Assistant
Step 5: コンパイル確認
Assistant
コンパイル通りました。clippy も確認します。
Assistant
全412テスト通過、clippy も警告なしです。
Assistant
全ステップ完了しました。最終的な変更内容を確認しておきます。
Assistant
実装が完了しました。変更は2ファイル、計43行追加 / 6行削除です。
変更サマリ
src/cli/prompt/starship.rs(+39/-4)PromptCache構造体を追加(left / right / continuation の3種のプロンプト出力を保持)StarshipPromptにcache: Mutex<Option<PromptCache>>フィールドを追加mark_dirty()メソッドを追加(キャッシュをNoneにリセット)render_prompt_left()— キャッシュがNoneなら全3種を一括生成して保存、以降はキャッシュを返すrender_prompt_right()/render_prompt_multiline_indicator()— キャッシュがあればそのまま返す
src/cli/prompt/mod.rs(+4/-2)refresh_git_status()で Starship バリアントの場合にmark_dirty()を呼ぶように変更
効果
- Before: キーストローク1回ごとに
starship promptを3回spawn → 大規模gitリポで ~500ms/キーストローク のブロッキング - After: コマンド実行後の1回のみ3回spawn → キーストローク中は 0ms(キャッシュ返却のみ)
- User
testやclippyを実行するときは
make checkを実行して Assistant
了解です。
make checkを実行します。Assistant
make check全項目パスしました。fmt / check / clippy / test(412テスト)すべて問題ありません。