perf(download): reduce copy buffer size to 4KB, stream directly to disk #162
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/pget!162
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/memory-optimization"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Reduce per-chunk copy buffer from 32KB (io.Copy default) to 4KB. Data already streams directly to disk with no in-memory accumulation.
Why
Lower memory footprint during parallel downloads. With 3 concurrent workers, peak buffer usage drops from 96KB to 12KB.
Implementation
copyBufSize = 4 * 1024constantrunRangeDownload:io.CopyBuffer(ws, io.LimitReader(reader, expected), buf)replacesio.CopyN(ws, reader, expected)(which allocated 32KB internally)runFullDownload:io.CopyBuffer(file, reader, buf)replacesio.Copy(file, reader)Testing
go test -race ./...— all passgo build ./...,go vet ./...,golangci-lint run— all cleanBreaking Changes
None
Closes #115, #113, #114
Review: APPROVED
Verification
go vet ./...— ✅ passesgo build ./...— ✅ passesgo test -race ./...— ✅ all passChanges
internal/downloader/download.go—copyBufSize = 4KBconstant;io.CopyBufferreplacesio.CopyN/io.Copyfor explicit buffer controlMemory impact
io.CopyNinternally allocates 32KB buffer per callio.CopyBufferwith 4KB = 8x reduction per-chunkCloses #113, #114, #115 on merge.