From 69b959c9c673857a32bca0d2653a64bc77bb9d94 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 21 Jan 2026 05:17:35 +0100 Subject: [PATCH] perf: improve terminal batching for snappier UI response Flush terminal batch immediately when size exceeds 1KB instead of waiting for the 16ms timeout. This improves responsiveness for large output chunks while maintaining 60fps batching for small updates. Co-Authored-By: Claude Opus 4.5 --- src/web/server.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/web/server.ts b/src/web/server.ts index 77f47f01..a6bdee03 100644 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -1347,11 +1347,23 @@ export class WebServer extends EventEmitter { } // Batch terminal data for better performance (60fps) + // Flushes immediately if batch > 1KB for snappier response to large outputs private batchTerminalData(sessionId: string, data: string): void { const existing = this.terminalBatches.get(sessionId) || ''; - this.terminalBatches.set(sessionId, existing + data); + const newBatch = existing + data; + this.terminalBatches.set(sessionId, newBatch); - // Start batch timer if not already running + // Flush immediately if batch is large (>1KB) for responsiveness + if (newBatch.length > 1024) { + if (this.terminalBatchTimer) { + clearTimeout(this.terminalBatchTimer); + this.terminalBatchTimer = null; + } + this.flushTerminalBatches(); + return; + } + + // Start batch timer if not already running (16ms = 60fps) if (!this.terminalBatchTimer) { this.terminalBatchTimer = setTimeout(() => { this.flushTerminalBatches();