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 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-21 05:17:35 +01:00
co-authored by Claude Opus 4.5
parent a21f0646e0
commit 69b959c9c6
+14 -2
View File
@@ -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();