1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 11:31:46 +00:00

Merge pull request #295 from JackPhallen/fix/cap-scanner-buffer-size

fix: cap entryChan buffer to prevent memory spikes
This commit is contained in:
Tw93
2026-01-12 11:46:00 +08:00
committed by GitHub

View File

@@ -53,7 +53,15 @@ func scanPathConcurrent(root string, filesScanned, dirsScanned, bytesScanned *in
var wg sync.WaitGroup
// Collect results via channels.
entryChan := make(chan dirEntry, len(children))
// Cap buffer size to prevent memory spikes with huge directories.
entryBufSize := len(children)
if entryBufSize > 4096 {
entryBufSize = 4096
}
if entryBufSize < 1 {
entryBufSize = 1
}
entryChan := make(chan dirEntry, entryBufSize)
largeFileChan := make(chan fileEntry, maxLargeFiles*2)
var collectorWg sync.WaitGroup