docs: 合并性能分析报告并优化内存管理

将 performance-reporter.md 合入 memory-peak-analysis.md,统一分析文档。
代码优化包括:compact 峰值释放、GC 阈值触发、虚拟滚动参数调优、
HybridTransport 队列缩减、无界缓存加 LRU 淘汰、taskSummary 避免数组拷贝。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-05-02 09:11:12 +08:00
parent ef10ad2839
commit 0977b0520e
8 changed files with 193 additions and 166 deletions

View File

@@ -521,7 +521,7 @@ export async function compactConversation(
}
// Store the current file state before clearing
const preCompactReadFileState = cacheToObject(context.readFileState)
let preCompactReadFileState = cacheToObject(context.readFileState)
// Clear the cache
context.readFileState.clear()
@@ -543,6 +543,9 @@ export async function compactConversation(
),
createAsyncAgentAttachmentsIfNeeded(context),
])
// Release the readFileState snapshot — it can hold 25+ MB of file content
preCompactReadFileState =
undefined as unknown as typeof preCompactReadFileState
const postCompactFileAttachments: AttachmentMessage[] = [
...fileAttachments,
@@ -649,6 +652,8 @@ export async function compactConversation(
// Extract compaction API usage metrics
const compactionUsage = getTokenUsage(summaryResponse)
// Release the full API response — it holds content blocks + usage metadata
summaryResponse = undefined as unknown as typeof summaryResponse
const querySourceForEvent =
recompactionInfo?.querySource ?? context.options.querySource ?? 'unknown'
@@ -922,7 +927,7 @@ export async function partialCompactConversation(
}
// Store the current file state before clearing
const preCompactReadFileState = cacheToObject(context.readFileState)
let preCompactReadFileState = cacheToObject(context.readFileState)
context.readFileState.clear()
context.loadedNestedMemoryPaths?.clear()
// Intentionally NOT resetting sentSkillNames — see compactConversation()
@@ -937,6 +942,9 @@ export async function partialCompactConversation(
),
createAsyncAgentAttachmentsIfNeeded(context),
])
// Release the readFileState snapshot — it can hold 25+ MB of file content
preCompactReadFileState =
undefined as unknown as typeof preCompactReadFileState
const postCompactFileAttachments: AttachmentMessage[] = [
...fileAttachments,
@@ -992,6 +1000,8 @@ export async function partialCompactConversation(
summaryResponse,
])
const compactionUsage = getTokenUsage(summaryResponse)
// Release the full API response — it holds content blocks + usage metadata
summaryResponse = undefined as unknown as typeof summaryResponse
logEvent('tengu_partial_compact', {
preCompactTokenCount,