mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 04:05:10 +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:
@@ -53,7 +53,15 @@ func scanPathConcurrent(root string, filesScanned, dirsScanned, bytesScanned *in
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
// Collect results via channels.
|
// 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)
|
largeFileChan := make(chan fileEntry, maxLargeFiles*2)
|
||||||
|
|
||||||
var collectorWg sync.WaitGroup
|
var collectorWg sync.WaitGroup
|
||||||
|
|||||||
Reference in New Issue
Block a user