mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 11:31:46 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user