perf: replace JSON.stringify equality with fast-deep-equal (#23370)
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
||||
import ProfileImage from './ProfileImage.svelte';
|
||||
import { WEBUI_BASE_URL } from '$lib/constants';
|
||||
import equal from 'fast-deep-equal';
|
||||
const i18n = getContext('i18n');
|
||||
dayjs.extend(localizedFormat);
|
||||
|
||||
@@ -66,7 +67,7 @@
|
||||
if (source) {
|
||||
if (message.content !== source.content || message.done !== source.done) {
|
||||
message = structuredClone(source);
|
||||
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||
} else if (!equal(message, source)) {
|
||||
message = structuredClone(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
removeAllDetails
|
||||
} from '$lib/utils';
|
||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||
import equal from 'fast-deep-equal';
|
||||
|
||||
import Name from './Name.svelte';
|
||||
import ProfileImage from './ProfileImage.svelte';
|
||||
@@ -127,7 +128,7 @@
|
||||
// Avoids 2x O(n) JSON.stringify calls that are always true during streaming anyway
|
||||
if (message.content !== source.content || message.done !== source.done) {
|
||||
message = structuredClone(source);
|
||||
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||
} else if (!equal(message, source)) {
|
||||
// Slow path: full comparison for infrequent changes (sources, annotations, status, etc.)
|
||||
message = structuredClone(source);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import StatusItem from './StatusHistory/StatusItem.svelte';
|
||||
import equal from 'fast-deep-equal';
|
||||
export let statusHistory = [];
|
||||
export let expand = false;
|
||||
|
||||
@@ -21,10 +22,7 @@
|
||||
status = history.at(-1);
|
||||
}
|
||||
|
||||
$: if (
|
||||
statusHistory.length !== history.length ||
|
||||
JSON.stringify(statusHistory) !== JSON.stringify(history)
|
||||
) {
|
||||
$: if (!equal(statusHistory, history)) {
|
||||
history = statusHistory;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { user as _user } from '$lib/stores';
|
||||
import { copyToClipboard as _copyToClipboard, formatDate } from '$lib/utils';
|
||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||
import equal from 'fast-deep-equal';
|
||||
|
||||
import Name from './Name.svelte';
|
||||
import ProfileImage from './ProfileImage.svelte';
|
||||
@@ -58,7 +59,7 @@
|
||||
if (source) {
|
||||
if (message.content !== source.content) {
|
||||
message = structuredClone(source);
|
||||
} else if (JSON.stringify(message) !== JSON.stringify(source)) {
|
||||
} else if (!equal(message, source)) {
|
||||
message = structuredClone(source);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user