MoonshotAI / MoonshotAI/kimi-cli
Bottom toolbar git subprocess calls cause typing lag at normal prompt
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
Bottom toolbar git subprocess calls cause typing lag at normal prompt
Summary
During normal prompt typing (no active turn, no modal, no completion menu), the bottom toolbar's git branch/status subprocess calls cause noticeable keystroke lag. This was isolated via binary search: the lag disappears when _get_git_branch() and _get_git_status() are removed from _render_bottom_toolbar().
Diagnostic evidence
We tested incrementally by stripping _render_bottom_toolbar() down to return FormattedText([]) and restoring sections one by one:
| Configuration | Typing smooth? |
|---|---|
| Bare prompt (no toolbar, no refresh, static message) | ✅ Smooth |
| Full prompt message restored | ✅ Smooth |
| Full bottom toolbar without git branch/status calls | ✅ Smooth |
| Stock bottom toolbar with git branch/status calls | ❌ Laggy |
The lag is present even when no turn is running and even with complete_while_typing=False, so it is purely a rendering/refresh overhead issue.
Likely root cause
_render_bottom_toolbar() calls _get_git_branch() and _get_git_status() on every UI redraw. Both use cached subprocesses (5s TTL for branch, 15s TTL for status), but on every redraw the code still:
- Calls
state.proc.poll()on the cached subprocess - If finished, calls
state.proc.communicate()to read stdout - Re-computes
_format_git_badge()and string widths
When combined with prompt_toolkit redrawing on every keystroke, this subprocess polling + string formatting overhead creates per-keystroke lag — especially noticeable in Ghostty on a large (5K) display where redraw frequency is high.
Suggested fixes
-
Throttle git status to the background refresh task instead of querying on every toolbar render. The bottom toolbar should read from a cached variable that the
_refresh()loop updates at most every 1–5 seconds, rather than evaluating the subprocess state on every keystroke. -
Move git metadata into the background refresh task alongside context usage and tip rotation, so
_render_bottom_toolbar()becomes a pure formatter reading cached values. -
Add memoization to
_render_bottom_toolbar()— if terminal width, CWD, git branch, git status, and background task count haven't changed since the last render, return the previously computedFormattedTextwithout re-evaluating subprocesses or re-allocating strings.
Related issues
- #2032 — Extreme typing latency in inline modal inputs (separate rendering bug, same symptom)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing _render_bottom_toolbar() and its calls to _get_git_branch() and _get_git_status(), then inspect the _refresh() loop and how prompt_toolkit redraws on typing. Done means git metadata is refreshed without per-keystroke subprocess work, the toolbar still displays current branch and status, and normal prompt typing no longer lags.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100