aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/object.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2022-10-26 18:12:39 +0100
committerPaulo Gomes <pjbgf@linux.com>2022-11-07 14:41:07 +0000
commit123cdde6f2f6282cb779e03745d384833ac1265b (patch)
treedc20c37ece501c3d66935c3832269393f2c18f63 /storage/filesystem/object.go
parent08cffa1efade914020497a73907763e8d3707a77 (diff)
downloadgo-git-123cdde6f2f6282cb779e03745d384833ac1265b.tar.gz
Use Sync.Pool pointers to optimise memory usage
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r--storage/filesystem/object.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 5c91bcd..21667fa 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os"
+ "sync"
"time"
"github.com/go-git/go-git/v5/plumbing"
@@ -419,10 +420,21 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
s.objectCache.Put(obj)
- _, err = io.Copy(w, r)
+ bufp := copyBufferPool.Get().(*[]byte)
+ buf := *bufp
+ _, err = io.CopyBuffer(w, r, buf)
+ copyBufferPool.Put(bufp)
+
return obj, err
}
+var copyBufferPool = sync.Pool{
+ New: func() interface{} {
+ b := make([]byte, 32*1024)
+ return &b
+ },
+}
+
// Get returns the object with the given hash, by searching for it in
// the packfile.
func (s *ObjectStorage) getFromPackfile(h plumbing.Hash, canBeDelta bool) (