From 033fd7cb1196f3d36fb41aa20fb472f49eccf649 Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Sat, 26 Sep 2026 13:55:20 +0300 Subject: [PATCH] render the transcript again only when its body width changes SetSize rebuilt every settled row through glamour on every call, and the glance poll calls it every 3s whether or not anything moved: about 14ms and 27MB of garbage each time with a full history. settled rows depend only on the body width, so a height or sidebar change now just refreshes the viewport. --- cli/internal/tui/chat.go | 8 ++++++-- cli/internal/tui/glance_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/internal/tui/chat.go b/cli/internal/tui/chat.go index 0dd802a9..9aff08cb 100644 --- a/cli/internal/tui/chat.go +++ b/cli/internal/tui/chat.go @@ -540,14 +540,18 @@ func (m *ChatModel) SetSize(width, height int) { } m.Viewport.Width = transcriptWidth - m.Renderer.BodyWidth = min(100, available) m.TextArea.SetWidth(available) m.TextArea.SetHeight(m.maxPromptHeight()) m.RecoveryInput.Width = max(1, available-16) m.Viewport.Height = max(1, height-6-m.chromeRows()) - m.rebuildSettledLines() + // settled rows are rendered at the body width alone, so only a new body + // width renders them again + if body := min(100, available); body != m.Renderer.BodyWidth { + m.Renderer.BodyWidth = body + m.rebuildSettledLines() + } m.refreshViewportContent() } diff --git a/cli/internal/tui/glance_test.go b/cli/internal/tui/glance_test.go index 02c69222..5bb0973b 100644 --- a/cli/internal/tui/glance_test.go +++ b/cli/internal/tui/glance_test.go @@ -17,3 +17,23 @@ func TestWorkGlanceShowsStableItemIDBesidePendingCount(t *testing.T) { t.Fatalf("glance count should not be confused with item ID: %q", glance) } } + +// The glance poll and chrome changes resize the chat without changing its body +// width, and must not render the whole transcript again. +func TestResizeRendersTranscriptOnlyForNewBodyWidth(t *testing.T) { + m := NewChatModel(&daemon.Session{ID: "s"}, nil) + m.SetSize(140, 24) + m.appendSettledEntry(HistoryEntry{Kind: EntryAssistant, Speaker: "albedo", Text: "hello"}) + const kept = "rendered once" + m.settledLines[0] = kept + + m.Glances = []PageGlance{{Title: "pending work", Rows: []PageRow{{ID: "1", Text: "x"}}}} + m.SetSize(140, 30) + if m.settledLines[0] != kept { + t.Fatal("a resize keeping the body width rendered the transcript again") + } + m.SetSize(80, 30) + if m.settledLines[0] == kept { + t.Fatal("a narrower body should render the transcript again") + } +} -- knotmirror 0.0.1