perf(index): debounce lexical warmup after invalidation paths

This commit is contained in:
2026-02-14 22:08:21 +08:00
parent 300ed2798f
commit 3040a9387d

View File

@@ -173,6 +173,8 @@ function onSendKeydown(e) {
let hideApplyTimer = null; let hideApplyTimer = null;
const HIDE_APPLY_DEBOUNCE_MS = 250; const HIDE_APPLY_DEBOUNCE_MS = 250;
let lexicalWarmupTimer = null;
const LEXICAL_WARMUP_DEBOUNCE_MS = 500;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -358,6 +360,7 @@ async function handleAnchorGenerate() {
// L1 rebuild only if new chunks were added (usually 0 in normal chat) // L1 rebuild only if new chunks were added (usually 0 in normal chat)
if (chunkResult.built > 0) { if (chunkResult.built > 0) {
invalidateLexicalIndex(); invalidateLexicalIndex();
scheduleLexicalWarmup();
} }
await sendAnchorStatsToFrame(); await sendAnchorStatsToFrame();
@@ -623,6 +626,7 @@ async function maybeAutoExtractL0() {
// L1 rebuild only if new chunks were added // L1 rebuild only if new chunks were added
if (chunkResult.built > 0) { if (chunkResult.built > 0) {
invalidateLexicalIndex(); invalidateLexicalIndex();
scheduleLexicalWarmup();
} }
await sendAnchorStatsToFrame(); await sendAnchorStatsToFrame();
@@ -1003,6 +1007,16 @@ function applyHideStateDebounced() {
}, HIDE_APPLY_DEBOUNCE_MS); }, HIDE_APPLY_DEBOUNCE_MS);
} }
function scheduleLexicalWarmup(delayMs = LEXICAL_WARMUP_DEBOUNCE_MS) {
clearTimeout(lexicalWarmupTimer);
const scheduledChatId = getContext().chatId || null;
lexicalWarmupTimer = setTimeout(() => {
lexicalWarmupTimer = null;
if (isChatStale(scheduledChatId)) return;
warmupIndex();
}, delayMs);
}
async function clearHideState() { async function clearHideState() {
// 暴力全量 unhide确保立刻恢复 // 暴力全量 unhide确保立刻恢复
await unhideAllMessages(); await unhideAllMessages();
@@ -1424,6 +1438,7 @@ async function handleMessageDeleted(scheduledChatId) {
} }
invalidateLexicalIndex(); invalidateLexicalIndex();
scheduleLexicalWarmup();
await sendAnchorStatsToFrame(); await sendAnchorStatsToFrame();
await sendVectorStatsToFrame(); await sendVectorStatsToFrame();
@@ -1673,6 +1688,8 @@ function unregisterEvents() {
events.cleanup(); events.cleanup();
events = null; events = null;
activeChatId = null; activeChatId = null;
clearTimeout(lexicalWarmupTimer);
lexicalWarmupTimer = null;
$(".xiaobaix-story-summary-btn").remove(); $(".xiaobaix-story-summary-btn").remove();
hideOverlay(); hideOverlay();