Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Add smallObjectThreshold constant instead of magic number.
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Navara <[email protected]>
  • Loading branch information
filipnavara committed Sep 26, 2018
1 parent 930ff6a commit acda664
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion plumbing/format/packfile/packfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ var (
ErrZLib = NewError("zlib reading error")
)

// When reading small objects from packfile it is beneficial to do so at
// once to exploit the buffered I/O. In many cases the objects are so small
// that they were already loaded to memory when the object header was
// loaded from the packfile. Wrapping in FSObject would cause this buffered
// data to be thrown away and then re-read later, with the additional
// seeking causing reloads from disk. Objects smaller than this threshold
// are now always read to memory and stored in cache instead of being
// wrapped in FSObject.
const smallObjectThreshold = 16 * 1024

// Packfile allows retrieving information from inside a packfile.
type Packfile struct {
idxfile.Index
Expand Down Expand Up @@ -208,7 +218,7 @@ func (p *Packfile) objectAtOffset(offset int64) (plumbing.EncodedObject, error)

// If we have no filesystem, we will return a MemoryObject instead
// of an FSObject.
if p.fs == nil || h.Length <= 16*1024 {
if p.fs == nil || h.Length <= smallObjectThreshold {
return p.getNextObject(h)
}

Expand Down

0 comments on commit acda664

Please sign in to comment.