1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 13:16:47 +00:00

Cap entryChan buffer to prevent memory spikes

Cap buffer at 4096. All entries still process normally—producers just briefly block if
the buffer fills, which is negligible since the collector drains it quickly.
This commit is contained in:
Jack Phallen
2026-01-11 10:26:57 -05:00
parent 54be4e30a2
commit 8870141923

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