diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-09-04 19:43:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-04 19:43:36 +0200 |
commit | f9879dd043f84936a1f8acb8a53b74332a7ae135 (patch) | |
tree | 13283ed091249f601ceacd7c64a3467c5f4eac78 /plumbing/format/packfile/scanner.go | |
parent | 770800d980ba7e0af40502324d15ed50445a3291 (diff) | |
parent | 6a46a7eb543789c7012bf0f964e1b6b38eca150c (diff) | |
download | go-git-f9879dd043f84936a1f8acb8a53b74332a7ae135.tar.gz |
Merge pull request #578 from erizocosmico/perf/reduce-gc-pressv4.0.0-rc15
packfile: improve performance a little by reducing gc pressure
Diffstat (limited to 'plumbing/format/packfile/scanner.go')
-rw-r--r-- | plumbing/format/packfile/scanner.go | 15 |
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 } |