From c6574f4232efe259f225d443df5db442fa240052 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Sat, 18 Dec 2021 01:15:50 -0500 Subject: Performance (Try 3): Experiment with preallocating buffers. --- lbc/lbc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lbc') diff --git a/lbc/lbc.go b/lbc/lbc.go index d0014dd..5cfcf9f 100644 --- a/lbc/lbc.go +++ b/lbc/lbc.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "io/ioutil" "net/http" "sync/atomic" ) @@ -90,8 +91,9 @@ func (lbd *LoadBearingConnectionDownload) doDownload(ctx context.Context) { lbd.valid = false return } + buff := make([]byte, 500*1024*1024) cr := &countingReader{n: &lbd.downloaded, ctx: ctx, readable: get.Body} - _, _ = io.ReadAll(cr) + _, _ = io.CopyBuffer(ioutil.Discard, cr, buff) lbd.valid = false get.Body.Close() if lbd.debug { -- cgit v1.2.3