Skip to content

perf(tui2): reduce unnecessary redraws#8681

Merged
joshka-oai merged 2 commits intomainfrom
joshka/tui2-redraw-gating
Jan 2, 2026
Merged

perf(tui2): reduce unnecessary redraws#8681
joshka-oai merged 2 commits intomainfrom
joshka/tui2-redraw-gating

Conversation

@joshka-oai
Copy link
Collaborator

This reduces unnecessary frame scheduling in codex-tui2.

Changes:

  • Gate redraw scheduling for streaming deltas when nothing visible changes.
  • Avoid a redraw feedback loop from footer transcript UI state updates.

Why:

  • Streaming deltas can arrive at very high frequency; redrawing on every delta can drive a near-constant render loop.
  • BottomPane was requesting another frame after every Draw even when the derived transcript UI state was unchanged.

Testing:

  • cargo test -p codex-tui2

Manual sampling:

  • sample "$(pgrep -n codex-tui2)" 3 -file /tmp/tui2.idle.after.sample.txt
  • sample "$(pgrep -n codex-tui2)" 3 -file /tmp/tui2.streaming.after.sample.txt

During streaming, agent deltas can arrive at very high frequency.
Scheduling a redraw for every delta drives a near-constant render loop
(clamped by FrameRequester) even when newline-gated streaming hasn't
produced any new visible transcript lines yet.

Only schedule a redraw for deltas that cause an immediate visible change
(e.g. flushing an active cell group or inserting the final-message
separator). Otherwise, rely on commit ticks to request redraws when a
committed history cell is actually appended.
App publishes derived transcript viewport state to the footer after every
draw. BottomPane was unconditionally scheduling another frame when
receiving that state, even when nothing changed.

This created a self-sustaining redraw loop (clamped by FrameRequester)
and burned CPU while visually idle.

Only request a redraw when the derived transcript UI state
(scrolled/selection/position/copy key) actually changes.
@joshka-oai joshka-oai enabled auto-merge (squash) January 2, 2026 20:09
@joshka-oai joshka-oai merged commit 3cfa4bc into main Jan 2, 2026
26 checks passed
@joshka-oai joshka-oai deleted the joshka/tui2-redraw-gating branch January 2, 2026 20:16
@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants