fix(ui): prevent memory leak in diff view with many modified files

- Add LRU eviction to diffCache (max 30 entries / 20MB)
- Single-file mode: render only selected diff, not all hidden ones
- Stacked mode: collapse files beyond first 10 by default
- Limit DiffWorkerProvider warmup to 10 files
- Reduce worker pool size (4 to 2) and AST cache (200 to 50)
This commit is contained in:
Bohdan Triapitsyn
2026-01-28 12:29:01 +02:00
parent 8c6eb3c44d
commit 91e8b9e1f5
3 changed files with 82 additions and 34 deletions
@@ -27,6 +27,9 @@ const PRELOAD_LANGS: SupportedLanguages[] = [
'bash',
];
// Limit warmup to prevent memory bloat with many modified files
const WARMUP_MAX_FILES = 10;
// Matches cache key logic in `packages/ui/src/components/views/PierreDiffViewer.tsx`
function getPierreCacheKey(fileName: string, original: string, modified: string): string {
const sampleOriginal = original.length > 100
@@ -107,7 +110,9 @@ const WorkerPoolWarmup: React.FC<{ children: React.ReactNode }> = ({ children })
let cancelled = false;
let cancelScheduled: (() => void) | null = null;
const entries = Array.from(dirState.diffCache.entries());
// Limit entries to prevent memory bloat with many modified files
const allEntries = Array.from(dirState.diffCache.entries());
const entries = allEntries.slice(0, WARMUP_MAX_FILES);
let index = 0;
@@ -190,8 +195,8 @@ export const DiffWorkerProvider: React.FC<DiffWorkerProviderProps> = ({ children
<WorkerPoolContextProvider
poolOptions={{
workerFactory,
poolSize: 4,
totalASTLRUCacheSize: 200,
poolSize: 2,
totalASTLRUCacheSize: 50,
}}
highlighterOptions={highlighterOptions}
>