mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-07 16:09:43 +02:00
perf: add input batching for rapid keystrokes
Implement input coalescing at 60fps (16ms intervals): - Batch regular character input to reduce API calls - Flush immediately for control characters (Enter, Ctrl+C, etc.) - Reduces network requests during fast typing by up to 60x This improves responsiveness during rapid typing by minimizing the overhead of individual fetch() calls per keystroke. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+32
-4
@@ -142,15 +142,43 @@ class ClaudemanApp {
|
|||||||
const resizeObserver = new ResizeObserver(throttledResize);
|
const resizeObserver = new ResizeObserver(throttledResize);
|
||||||
resizeObserver.observe(container);
|
resizeObserver.observe(container);
|
||||||
|
|
||||||
// Handle keyboard input
|
// Handle keyboard input with batching for rapid keystrokes
|
||||||
this.terminal.onData((data) => {
|
this._pendingInput = '';
|
||||||
if (this.activeSessionId) {
|
this._inputFlushTimeout = null;
|
||||||
|
this._inputFlushDelay = 16; // Flush at 60fps max
|
||||||
|
|
||||||
|
const flushInput = () => {
|
||||||
|
if (this._pendingInput && this.activeSessionId) {
|
||||||
|
const input = this._pendingInput;
|
||||||
|
this._pendingInput = '';
|
||||||
fetch(`/api/sessions/${this.activeSessionId}/input`, {
|
fetch(`/api/sessions/${this.activeSessionId}/input`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ input: data })
|
body: JSON.stringify({ input })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this._inputFlushTimeout = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.terminal.onData((data) => {
|
||||||
|
if (this.activeSessionId) {
|
||||||
|
this._pendingInput += data;
|
||||||
|
|
||||||
|
// Flush immediately for control characters (Enter, Ctrl+C, etc.)
|
||||||
|
if (data.charCodeAt(0) < 32 || data.length > 1) {
|
||||||
|
if (this._inputFlushTimeout) {
|
||||||
|
clearTimeout(this._inputFlushTimeout);
|
||||||
|
this._inputFlushTimeout = null;
|
||||||
|
}
|
||||||
|
flushInput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Batch regular input at 60fps
|
||||||
|
if (!this._inputFlushTimeout) {
|
||||||
|
this._inputFlushTimeout = setTimeout(flushInput, this._inputFlushDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user