perf: use structuredClone and fast-path comparison in UserMessage (#22098)
Same optimization as the merged ResponseMessage PR: replace JSON.parse(JSON.stringify()) with structuredClone and add an O(1) fast-path check on content before falling back to full JSON.stringify comparison.
This commit is contained in:
@@ -52,10 +52,15 @@
|
|||||||
let messageEditTextAreaElement: HTMLTextAreaElement;
|
let messageEditTextAreaElement: HTMLTextAreaElement;
|
||||||
let editScrollContainer: HTMLDivElement;
|
let editScrollContainer: HTMLDivElement;
|
||||||
|
|
||||||
let message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
let message = structuredClone(history.messages[messageId]);
|
||||||
$: if (history.messages) {
|
$: if (history.messages) {
|
||||||
if (JSON.stringify(message) !== JSON.stringify(history.messages[messageId])) {
|
const source = history.messages[messageId];
|
||||||
message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
if (source) {
|
||||||
|
if (message.content !== source.content) {
|
||||||
|
message = structuredClone(source);
|
||||||
|
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||||
|
message = structuredClone(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user