Skip to content

Commit b16dc44

Browse files
committed
fix: prevent memory accumulation in activeBatchPromises
- Convert activeBatchPromises from Array to Set for efficient removal - Clean up completed promises immediately after they finish - Remove unnecessary Array.from() when passing Set to Promise.all - Prevents unbounded growth of promise references during large scans
1 parent e4863fc commit b16dc44

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/services/code-index/processors/scanner.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class DirectoryScanner implements IDirectoryScanner {
9797
let currentBatchBlocks: CodeBlock[] = []
9898
let currentBatchTexts: string[] = []
9999
let currentBatchFileInfos: { filePath: string; fileHash: string; isNew: boolean }[] = []
100-
const activeBatchPromises: Promise<void>[] = []
100+
const activeBatchPromises = new Set<Promise<void>>()
101101

102102
// Initialize block counter
103103
let totalBlockCount = 0
@@ -171,7 +171,12 @@ export class DirectoryScanner implements IDirectoryScanner {
171171
onBlocksIndexed,
172172
),
173173
)
174-
activeBatchPromises.push(batchPromise)
174+
activeBatchPromises.add(batchPromise)
175+
176+
// Clean up completed promises to prevent memory accumulation
177+
batchPromise.finally(() => {
178+
activeBatchPromises.delete(batchPromise)
179+
})
175180
}
176181
} finally {
177182
release()
@@ -237,7 +242,12 @@ export class DirectoryScanner implements IDirectoryScanner {
237242
const batchPromise = batchLimiter(() =>
238243
this.processBatch(batchBlocks, batchTexts, batchFileInfos, scanWorkspace, onError, onBlocksIndexed),
239244
)
240-
activeBatchPromises.push(batchPromise)
245+
activeBatchPromises.add(batchPromise)
246+
247+
// Clean up completed promises to prevent memory accumulation
248+
batchPromise.finally(() => {
249+
activeBatchPromises.delete(batchPromise)
250+
})
241251
} finally {
242252
release()
243253
}

0 commit comments

Comments
 (0)