From 6a46a7eb543789c7012bf0f964e1b6b38eca150c Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Mon, 4 Sep 2017 18:23:26 +0200 Subject: packfile: improve performance a little by reducing gc pressure Signed-off-by: Miguel Molina --- plumbing/format/packfile/scanner.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'plumbing/format/packfile/scanner.go') 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 } -- cgit