aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/scanner.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2017-09-04 18:23:26 +0200
committerMiguel Molina <miguel@erizocosmi.co>2017-09-04 18:23:26 +0200
commit6a46a7eb543789c7012bf0f964e1b6b38eca150c (patch)
tree13283ed091249f601ceacd7c64a3467c5f4eac78 /plumbing/format/packfile/scanner.go
parent770800d980ba7e0af40502324d15ed50445a3291 (diff)
downloadgo-git-6a46a7eb543789c7012bf0f964e1b6b38eca150c.tar.gz
packfile: improve performance a little by reducing gc pressure
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/scanner.go')
-rw-r--r--plumbing/format/packfile/scanner.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/plumbing/format/packfile/scanner.go b/plumbing/format/packfile/scanner.go
index 1dab2f2..d2d776f 100644
--- a/plumbing/format/packfile/scanner.go
+++ b/plumbing/format/packfile/scanner.go
@@ -9,6 +9,7 @@ import (
"hash/crc32"
"io"
stdioutil "io/ioutil"
+ "sync"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/utils/binary"
@@ -291,10 +292,18 @@ func (s *Scanner) copyObject(w io.Writer) (n int64, err error) {
}
defer ioutil.CheckClose(s.zr, &err)
- n, err = io.Copy(w, s.zr)
+ buf := byteSlicePool.Get().([]byte)
+ n, err = io.CopyBuffer(w, s.zr, buf)
+ byteSlicePool.Put(buf)
return
}
+var byteSlicePool = sync.Pool{
+ New: func() interface{} {
+ return make([]byte, 32*1024)
+ },
+}
+
// SeekFromStart sets a new offset from start, returns the old position before
// the change.
func (s *Scanner) SeekFromStart(offset int64) (previous int64, err error) {
@@ -324,7 +333,9 @@ func (s *Scanner) Checksum() (plumbing.Hash, error) {
// Close reads the reader until io.EOF
func (s *Scanner) Close() error {
- _, err := io.Copy(stdioutil.Discard, s.r)
+ buf := byteSlicePool.Get().([]byte)
+ _, err := io.CopyBuffer(stdioutil.Discard, s.r, buf)
+ byteSlicePool.Put(buf)
return err
}