From 02e01848d6dfa9d680e197126428131fb03e6c18 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 2 Mar 2026 15:30:51 -0600 Subject: [PATCH] Batch serial reads before rendering to improve ANSI throughput Drain all available serial data before calling FlipToScreen so overlapping screen changes collapse into a single GDI render pass. Messages are checked between chunks to keep keyboard responsive. Co-Authored-By: Claude Opus 4.6 --- delphi/TESTMAIN.PAS | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/delphi/TESTMAIN.PAS b/delphi/TESTMAIN.PAS index e6114ff..1f35e13 100644 --- a/delphi/TESTMAIN.PAS +++ b/delphi/TESTMAIN.PAS @@ -189,18 +189,35 @@ begin if FDone then Break; - { Poll serial data -- read one chunk per iteration } + { Drain all available serial data before rendering. Batching } + { many chunks into one render pass avoids per-chunk GDI overhead. } + { Messages are checked between chunks so keyboard stays responsive.} HasData := False; if FComm.PortOpen then begin S := FComm.Input; - if Length(S) > 0 then + while (Length(S) > 0) and not FDone do begin FAnsi.WriteDeferred(S); HasData := True; + { Check for messages between chunks } + while PeekMessage(Msg, 0, 0, 0, pm_Remove or pm_NoYield) do + begin + if Msg.message = wm_Quit then + begin + FDone := True; + Break; + end; + TranslateMessage(Msg); + DispatchMessage(Msg); + end; + S := FComm.Input; end; end; + if FDone then + Break; + { Tick blink (dirties rows if interval elapsed), then render } FAnsi.TickBlink; FAnsi.FlipToScreen;