Skip to content

Coalesce redraws to fix 100% CPU from full-screen agent TUIs#49

Merged
wfaderhold21 merged 1 commit into
mainfrom
topic/fix-tui-redraw-cpu
Jul 20, 2026
Merged

Coalesce redraws to fix 100% CPU from full-screen agent TUIs#49
wfaderhold21 merged 1 commit into
mainfrom
topic/fix-tui-redraw-cpu

Conversation

@wfaderhold21

Copy link
Copy Markdown
Owner

Full-screen agent TUIs (notably OpenCode) repaint continuously with byte-identical frames and never go output-quiet, which pinned the render loop at its 60 fps frame cap and burned a full core even when idle.

Two feedback paths forced this:

  • Every SessionBytes chunk flagged a redraw via the blanket needs_redraw at the end of handle_event.
  • The PTY reader emits a SessionCurrentLine heartbeat every ~20ms per session, each also flagging a redraw.

Gate both on real change, keyed on rendered content rather than session type so Claude/Codex benefit identically:

  • process_bytes hashes contents_formatted() and reports whether the visible frame changed; handle_session_bytes redraws only when a visible session's screen changed.
  • handle_session_current_line redraws only when state inference flips the session (its text is already carried by the vt100 screen).

State inference on the line path is untouched, so Waiting/Error detection is unchanged for all agents.

Full-screen agent TUIs (notably OpenCode) repaint continuously with
byte-identical frames and never go output-quiet, which pinned the render
loop at its 60 fps frame cap and burned a full core even when idle.

Two feedback paths forced this:
- Every SessionBytes chunk flagged a redraw via the blanket
  needs_redraw at the end of handle_event.
- The PTY reader emits a SessionCurrentLine heartbeat every ~20ms per
  session, each also flagging a redraw.

Gate both on real change, keyed on rendered content rather than session
type so Claude/Codex benefit identically:
- process_bytes hashes contents_formatted() and reports whether the
  visible frame changed; handle_session_bytes redraws only when a
  *visible* session's screen changed.
- handle_session_current_line redraws only when state inference flips
  the session (its text is already carried by the vt100 screen).

State inference on the line path is untouched, so Waiting/Error
detection is unchanged for all agents.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wfaderhold21
wfaderhold21 merged commit a7e98c4 into main Jul 20, 2026
2 checks passed
@wfaderhold21
wfaderhold21 deleted the topic/fix-tui-redraw-cpu branch July 20, 2026 19:55
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