mirror of
https://github.com/open-webui/open-webui.git
synced 2026-04-27 11:08:57 -05:00
perf: use structuredClone for message deep copies (#21948)
This commit is contained in:
@@ -60,10 +60,10 @@
|
||||
|
||||
let selectedModelIdx = null;
|
||||
|
||||
let message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
let message = structuredClone(history.messages[messageId]);
|
||||
$: if (history.messages) {
|
||||
if (JSON.stringify(message) !== JSON.stringify(history.messages[messageId])) {
|
||||
message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
message = structuredClone(history.messages[messageId]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,17 +119,17 @@
|
||||
export let messageId;
|
||||
export let selectedModels = [];
|
||||
|
||||
let message: MessageType = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
let message: MessageType = structuredClone(history.messages[messageId]);
|
||||
$: if (history.messages) {
|
||||
const source = history.messages[messageId];
|
||||
if (source) {
|
||||
// Fast path: O(1) check on the fields that change most often (content during streaming, done at end)
|
||||
// Avoids 2x O(n) JSON.stringify calls that are always true during streaming anyway
|
||||
if (message.content !== source.content || message.done !== source.done) {
|
||||
message = JSON.parse(JSON.stringify(source));
|
||||
message = structuredClone(source);
|
||||
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||
// Slow path: full comparison for infrequent changes (sources, annotations, status, etc.)
|
||||
message = JSON.parse(JSON.stringify(source));
|
||||
message = structuredClone(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user