Problem
The agent loop streams LLM tokens one at a time, each triggering a transcript re-render through ratatui's full layout pass. On long transcripts with active streaming, the render rate can lag the network arrival rate — users see token bursts followed by pauses rather than smooth output.
The persistence-actor fix (#) eliminates one source of stalls (sync I/O); render-pass cost is the next axis. Worth profiling separately before guessing.
Proposed solution
- Profile first.
cargo flamegraph --bin deepseek-tui while running a long-output session (--prompt "write a 5000-line markdown summary of every README in popular open-source rust projects"). Identify what's actually slow:
- ratatui layout pass cost
- text shaping / unicode-width recalc
- syntax highlighting (if any in transcript)
- serde serialization (if persistence still on hot path)
- history Vec re-allocation
- Coalesce streamed chunks. Currently each token-event triggers an event-loop tick. Buffer for ~16ms (one frame at 60fps) then emit one render. Drops token rate jitter.
- Damage tracking. ratatui re-renders the entire screen every frame. Track which lines changed since last frame; only re-shape those. Faster on long transcripts.
- Lazy line shaping. Only run unicode-width / wrapping on visible lines. Off-screen lines are kept as raw strings until scrolled into view.
Acceptance criteria
Related
Problem
The agent loop streams LLM tokens one at a time, each triggering a transcript re-render through ratatui's full layout pass. On long transcripts with active streaming, the render rate can lag the network arrival rate — users see token bursts followed by pauses rather than smooth output.
The persistence-actor fix (#) eliminates one source of stalls (sync I/O); render-pass cost is the next axis. Worth profiling separately before guessing.
Proposed solution
cargo flamegraph --bin deepseek-tuiwhile running a long-output session (--prompt "write a 5000-line markdown summary of every README in popular open-source rust projects"). Identify what's actually slow:Acceptance criteria
Related