Repository navigation
fix(cli): keep chat parser at full height so zarvis typing isn't laggy - #128
Merged
Merged
Conversation
#127 cut the steady-state replay_full cost, but typing was still slow. The real culprit: as the user types, the zarvis editor pane grows and `chat_area.height` shrinks, so render_terminal handed `replay` a smaller `rows` on (nearly) every keystroke. replay_full treats any rows change as a full O(history) vt100 rebuild — measured at ~26 ms/keystroke on a modest 300-cycle session in debug, and it scales linearly with history size. #127's steady-state test kept rows constant, so it never exercised this path. Fix it in the render layer instead of the parser: render the chat at the stable full pane height and show only its bottom `chat_area.height` rows (the editor pane covers the rest). Editor growth no longer changes the rows passed to `replay`, so the parser is never resized — and never rebuilt — per keystroke. A naive `set_size`-shrink was rejected: vt100 truncates from the bottom, dropping the most recent lines. Tool-block hit-rects are translated from full-screen rows into chat-area-relative rows (`translate_block_hits`); blocks scrolled above the slice are dropped, partially-visible ones clipped. No-editor-pane sessions (claude/codex/shell) get row_offset 0 — identical behavior. Tests: structural guard that editor growth doesn't resize the chat parser (and the shrunk chat still shows the newest content), plus unit coverage for the hit-rect translation.
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.
Problem
Typing into a zarvis prompt was still laggy after #127.
#127 cut the steady-state
replay_fullcost (per-frame history re-scan), but the actual typing path was never about steady state. As the user types, the zarvis editor pane grows and the chat area shrinks, sorender_terminalhandedItemHistory::replaya smallerrowson nearly every keystroke.replay_fulltreats anyrowschange as a full O(history) vt100 rebuild.Measured on a modest 300-cycle (~600-item) session in a debug build: ~26 ms per keystroke just for the chat rebuild — and it scales linearly with session length, so a long session is far worse. #127's steady-state test kept
rowsconstant, which is exactly why it passed while the lag remained.(The keystroke→
EditorStatedaemon round-trip is ~1.3 ms — confirmed by driving a real ollama-backed zarvis session over the socket — so the bottleneck was entirely the client-side render.)Fix
Solve it in the render layer rather than the parser. Render the chat at the stable full pane height and display only its bottom
chat_area.heightrows; the editor pane covers the rest. Editor growth no longer changes therowspassed toreplay, so the chat parser is never resized — and never rebuilt — per keystroke. Cost is independent of history size.A naive
set_size-on-shrink was rejected: vt100 truncates from the bottom, dropping the most recent lines (verified — it rendered content ~16 rows too high).Tool-block hit-rects are translated from full-screen rows into chat-area-relative rows via
translate_block_hits(blocks scrolled above the slice are dropped, partially-visible ones clipped, button zones survive only if the header row is visible). Sessions without an editor pane (claude/codex/shell) getrow_offset = 0— byte-for-byte identical behavior.Tests
zarvis_editor_growth_does_not_resize_chat_parser— structural, timing-free: growing the editor buffer must not change the chat parser's dims, and the shrunk chat must still show the most-recent content.translate_block_hits_shifts_clips_and_drops— hit-rect translation (identity / drop / clip / shift).🤖 Generated with Claude Code