perf: fast-path token comparison in CodeBlock (#22101)
During streaming, every token change triggers a full JSON.stringify comparison on the code block token object. Add an O(1) fast-path check on token.text and token.raw — the fields that actually change during streaming — before falling back to the expensive JSON.stringify comparison for infrequent structural changes.
This commit is contained in:
1 parent
73617ec7fa
commit
a0d6c209c3
1 file changed
+3
-1
@@ -364,7 +364,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$: if (token) {
|
$: if (token) {
|
||||||
if (JSON.stringify(token) !== JSON.stringify(_token)) {
|
if (token.text !== _token?.text || token.raw !== _token?.raw) {
|
||||||
|
_token = token;
|
||||||
|
} else if (JSON.stringify(token) !== JSON.stringify(_token)) {
|
||||||
_token = token;
|
_token = token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user