Skip to content

Commit d6223fb

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
perf: batch history reactive triggers to rAF in chatEventHandler
1 parent 730b432 commit d6223fb

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
@@ -535,7 +535,13 @@
535535
console.log('Unknown message type', data);
536536
}
537537
538-
history.messages[event.message_id] = message;
538+
if (type === 'chat:message:delta' || type === 'message' || type === 'status') {
539+
scheduleHistoryFlush();
540+
} else {
541+
cancelAnimationFrame(historyRAF);
542+
historyRAF = null;
543+
history.messages[event.message_id] = message;
544+
}
539545
}
540546
} else {
541547
// Non-active chat completion: queue stays in the global store.
@@ -1278,6 +1284,15 @@
12781284
12791285
let scrollRAF = null;
12801286
let contentsRAF = null;
1287+
let historyRAF = null;
1288+
const scheduleHistoryFlush = () => {
1289+
if (!historyRAF) {
1290+
historyRAF = requestAnimationFrame(() => {
1291+
historyRAF = null;
1292+
history = history;
1293+
});
1294+
}
1295+
};
12811296
const scheduleScrollToBottom = () => {
12821297
if (!scrollRAF) {
12831298
scrollRAF = requestAnimationFrame(async () => {

0 commit comments

Comments
 (0)