Skip to content

Commit 7ce1e94

Browse files
perf: batch history reactive triggers to rAF in chatEventHandler (open-webui#22947)
1 parent a9c5c78 commit 7ce1e94

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

0 commit comments

Comments
 (0)