perf: skip token parsing when raw content is unchanged (#22183)

This commit is contained in:
Algorithm5838 2026-03-06 23:08:12 +03:00 committed by GitHub
parent 47b007ef19
commit a25ecfa856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,6 +36,8 @@
let tokens = [];
let pendingUpdate = null;
let lastContent = '';
let lastParsedContent = '';
const options = {
throwOnError: false,
@ -56,7 +58,14 @@
});
const parseTokens = () => {
tokens = marked.lexer(replaceTokens(processResponseContent(content), model?.name, $user?.name));
if (content === lastContent) return;
lastContent = content;
const processed = replaceTokens(processResponseContent(content), model?.name, $user?.name);
if (processed === lastParsedContent) return;
lastParsedContent = processed;
tokens = marked.lexer(processed);
};
const updateHandler = (content) => {