perf(main): only redraw when state changed#428
Merged
Conversation
The diff renderer rebuilds every visible line on each draw, so the unconditional redraw every 100ms wastes CPU on idle and ships needless bytes over slow links. Track a needs_redraw flag set by input events, the update check, message expiry, persisted-session reloads, and in-flight PR work, and skip terminal.draw() when nothing changed. PR spinners keep animating because has_pending_pr_work() forces a redraw each tick while a forge fetch is in flight.
joaomendoncaa
pushed a commit
to joaomendoncaa/tuicr
that referenced
this pull request
Jun 26, 2026
The diff renderer rebuilds every visible line on each draw, so the unconditional redraw every 100ms wastes CPU on idle and ships needless bytes over slow links. Track a needs_redraw flag set by input events, the update check, message expiry, persisted-session reloads, and in-flight PR work, and skip terminal.draw() when nothing changed. PR spinners keep animating because has_pending_pr_work() forces a redraw each tick while a forge fetch is in flight.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following up on the discussion in #394, this is one of the smaller perf
patches I mentioned, with no async/streaming involved.
The main loop currently calls
terminal.draw()every 100ms regardlessof whether anything changed. The diff renderer rebuilds every visible
line on each draw, so on large diffs this burns CPU while idle and
ships needless escape sequences over slow links.
This adds a
needs_redrawflag set by:event::read()so the manycontinuepaths in the key handler still trigger a redraw)
animating and results paint as soon as they arrive)
When none of those fire,
terminal.draw()is skipped entirely.clear_expired_message()andpoll_persisted_session_changes()nowreturn
boolto report whether they touched visible state. The newhas_pending_pr_work()helper just ORs the six PR rx slots.Tested locally on a ~6k-line diff over a slow ssh hop: idle CPU drops
to zero and ratatui no longer re-emits the cursor-line attrs every
100ms.