Skip to content

perf(tui): keep long conversations responsive - #1119

Merged
liruifengv merged 7 commits into
mainfrom
perf/tui-keep-responsive
Jun 26, 2026
Merged

perf(tui): keep long conversations responsive#1119
liruifengv merged 7 commits into
mainfrom
perf/tui-keep-responsive

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — no linked issue; see Problem below.

Problem

In long conversations the TUI gets progressively sluggish. The transcript grows without bound and, on every frame, every message component is re-rendered in full even when nothing changed.

What changed

Two complementary changes keep the terminal responsive as history grows:

  • Cache each message component's rendered output across frames, so unchanged messages are not rendered again.
  • Bound the live transcript: only the most recent turns are kept in the component tree, and older thinking / tool steps within each turn are collapsed into a compact summary line.

The transcript thresholds are tunable via KIMI_CODE_TUI_* environment variables, and a value of 0 disables the corresponding feature.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Cache render(width) output in the transcript container and message components, returning cached lines when content, theme, and width are unchanged. Removes the per-frame full-transcript re-render that caused the TUI to lag as history grew.
Keep the TUI responsive as conversations grow by bounding the live
transcript:

- Sliding window: keep only the most recent 50 turns in the component
  tree; older turns are destroyed (entry + component).
- Step merging: within each turn, keep only the most recent 30
  thinking / tool steps rendered; older ones collapse into a summary.
- Expand (Ctrl+O) only reaches the most recent 3 turns.

All thresholds are overridable via KIMI_CODE_TUI_* env vars; 0
disables the corresponding feature.
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9aa23ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4830069d5d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts
# Conflicts:
#	apps/kimi-code/src/tui/components/messages/user-message.ts
#	apps/kimi-code/src/tui/kimi-tui.ts
@pkg-pr-new

pkg-pr-new Bot commented Jun 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@9aa23ef
npx https://pkg.pr.new/@moonshot-ai/kimi-code@9aa23ef

commit: 9aa23ef

@liruifengv
liruifengv merged commit b0b2aee into main Jun 26, 2026
9 checks passed
@liruifengv
liruifengv deleted the perf/tui-keep-responsive branch June 26, 2026 10:32
@github-actions github-actions Bot mentioned this pull request Jun 26, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Jul 11, 2026
* perf(tui): cache rendered message lines across frames

Cache render(width) output in the transcript container and message components, returning cached lines when content, theme, and width are unchanged. Removes the per-frame full-transcript re-render that caused the TUI to lag as history grew.

* perf(tui): bound transcript with sliding window and step merging

Keep the TUI responsive as conversations grow by bounding the live
transcript:

- Sliding window: keep only the most recent 50 turns in the component
  tree; older turns are destroyed (entry + component).
- Step merging: within each turn, keep only the most recent 30
  thinking / tool steps rendered; older ones collapse into a summary.
- Expand (Ctrl+O) only reaches the most recent 3 turns.

All thresholds are overridable via KIMI_CODE_TUI_* env vars; 0
disables the corresponding feature.

* chore: add changeset for tui transcript window

* chore(tui): remove KIMI_TUI_PERF render timing log

(cherry picked from commit b0b2aee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant