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:
Classic298 2026-03-01 20:46:05 +01:00 • committed by GitHub
parent 387225eb8b
commit 597883a179
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,10 +52,15 @@
let messageEditTextAreaElement: HTMLTextAreaElement;
let editScrollContainer: HTMLDivElement;
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]));
const source = history.messages[messageId];
if (source) {
if (message.content !== source.content) {
message = structuredClone(source);
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
message = structuredClone(source);
}
}
}