From 3f6b8f69fd066719ecddf64f5c9d5b8763b9546b Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Mon, 8 Jun 2026 12:32:33 +0300 Subject: [PATCH] fix(ui): raise pad redraw threshold above buffer cap to fix history scroll PAD_THRESHOLD (3000) sat below the buffer line cap (PAD_SIZE - PAD_SIZE/10 = 9000), so _win_ensure_pad_capacity() fired a full win_redraw() from the hot print path on every message once a chat exceeded 3000 rendered lines. During history paging this turned one redraw per fetch into dozens, corrupting per-entry y_start_pos (offset jumps, dropped/skipped messages) and causing ~10s lag per page. The flat-file backend was byte-identical across the regression; the fault was purely in the UI pad path from the upstream merge. Raise PAD_THRESHOLD to 12000 (above the cap) so the reclaim redraw only fires to drop dead pad space in long append-only sessions, never during scrolling. Also size the pad once to buffer->lines+100 in win_redraw() instead of shrinking to PAD_MIN_HEIGHT and regrowing per entry, removing the residual per-redraw wresize churn. --- src/ui/window.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 17a78ef2..f0ec5bbb 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -43,7 +43,7 @@ #include "ai/ai_client.h" static const int PAD_MIN_HEIGHT = 100; -static const int PAD_THRESHOLD = 3000; +static const int PAD_THRESHOLD = 12000; // above buffer cap (~9000): reclaims dead pad space, never fires while scrolling static gboolean _in_redraw = FALSE; static void @@ -2172,9 +2172,10 @@ win_redraw(ProfWin* window) unsigned int size = buffer_size(window->layout->buffer); _in_redraw = TRUE; - // shrink pad back to minimum size and erase it + // size the pad to fit the whole buffer (plus headroom) and erase it int cols = getmaxx(window->layout->win); - wresize(window->layout->win, PAD_MIN_HEIGHT, cols); + int needed = window->layout->buffer->lines + 100; + wresize(window->layout->win, MAX(needed, PAD_MIN_HEIGHT), cols); werase(window->layout->win); for (unsigned int i = 0; i < size; i++) {