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

@@ -551,9 +551,19 @@ export async function runHeadless(
proactiveModule.activateProactive('command')
}
// Periodically force a full GC to keep memory usage in check
// Periodically run GC to keep memory usage in check.
// Uses a memory threshold to trigger a forced (major) GC when RSS grows
// beyond 350MB — the incremental GC may not reclaim enough during peaks
// (compact, long sessions with many mounted DOM nodes).
if (typeof Bun !== 'undefined') {
const gcTimer = setInterval(Bun.gc, 1000)
const gcTimer = setInterval(() => {
const rss = process.memoryUsage.rss()
if (rss > 350 * 1024 * 1024) {
Bun.gc(true)
} else {
Bun.gc(false)
}
}, 1000)
gcTimer.unref()
}

View File

@@ -83,7 +83,7 @@ export class HybridTransport extends WebSocketTransport {
// SerialBatchEventUploader backpressure check). So set it high enough
// to be a memory bound only. Wire real backpressure in a follow-up
// once callers await.
maxQueueSize: 100_000,
maxQueueSize: 10_000,
baseDelayMs: 500,
maxDelayMs: 8000,
jitterMs: 1000,