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:
@@ -364,7 +364,9 @@
|
||||
};
|
||||
|
||||
$: 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user