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:
Classic298
2026-03-01 13:37:10 -05:00
committed by GitHub
parent 73617ec7fa
commit a0d6c209c3
@@ -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;
}
}