Skip to content

Commit 7b75c31

Browse files
committed
fix/try-fix-excessive-watcher-memory-usage
1 parent daf6483 commit 7b75c31

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • apps/array/src/main/services/file-watcher

apps/array/src/main/services/file-watcher/service.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {
1414

1515
const log = logger.scope("file-watcher");
1616

17-
const IGNORE_PATTERNS = ["**/node_modules/**", "**/.git/**"];
18-
const DEBOUNCE_MS = 100;
17+
const IGNORE_PATTERNS = ["**/node_modules/**", "**/.git/**", "**/.jj/**"];
18+
const DEBOUNCE_MS = 500;
19+
const BULK_THRESHOLD = 100;
1920

2021
interface PendingChanges {
2122
dirs: Set<string>;
@@ -177,6 +178,18 @@ export class FileWatcherService extends TypedEventEmitter<FileWatcherEvents> {
177178
}
178179

179180
private flushPending(repoPath: string, pending: PendingChanges): void {
181+
const totalChanges = pending.files.size + pending.deletes.size;
182+
183+
// For bulk changes, emit a single event instead of per-file events
184+
if (totalChanges > BULK_THRESHOLD) {
185+
this.emit(FileWatcherEvent.GitStateChanged, { repoPath });
186+
pending.dirs.clear();
187+
pending.files.clear();
188+
pending.deletes.clear();
189+
pending.timer = null;
190+
return;
191+
}
192+
180193
for (const dirPath of pending.dirs) {
181194
this.emit(FileWatcherEvent.DirectoryChanged, { repoPath, dirPath });
182195
}

0 commit comments

Comments
 (0)