Skip to content

Commit 9d8c9e7

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
perf: batch history reactive triggers to rAF in chatEventHandler
1 parent 5164c49 commit 9d8c9e7

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,13 @@
537537
console.log('Unknown message type', data);
538538
}
539539
540-
history.messages[event.message_id] = message;
540+
if (type === 'chat:message:delta' || type === 'message' || type === 'status') {
541+
scheduleHistoryFlush();
542+
} else {
543+
cancelAnimationFrame(historyRAF);
544+
historyRAF = null;
545+
history.messages[event.message_id] = message;
546+
}
541547
}
542548
} else {
543549
// Non-active chat completion: queue stays in the global store.
@@ -1281,6 +1287,15 @@
12811287
12821288
let scrollRAF = null;
12831289
let contentsRAF = null;
1290+
let historyRAF = null;
1291+
const scheduleHistoryFlush = () => {
1292+
if (!historyRAF) {
1293+
historyRAF = requestAnimationFrame(() => {
1294+
historyRAF = null;
1295+
history = history;
1296+
});
1297+
}
1298+
};
12841299
const scheduleScrollToBottom = () => {
12851300
if (!scrollRAF) {
12861301
scrollRAF = requestAnimationFrame(async () => {

0 commit comments

Comments
 (0)