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

Commit 44c9b31

Browse files
committed
Add smallObjectThreshold constant instead of magic number.
Signed-off-by: Filip Navara <[email protected]>
1 parent 930ff6a commit 44c9b31

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

plumbing/format/packfile/packfile.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ var (
2121
ErrZLib = NewError("zlib reading error")
2222
)
2323

24+
// When reading small objects from packfile it is beneficial to do so at
25+
// once to exploit the buffered I/O. In many cases the objects are so small
26+
// that they were already loaded to memory when the object header was
27+
// loaded from the packfile. Wrapping in FSObject would cause this buffered
28+
// data to be thrown away and then re-read later, with the additional
29+
// seeking causing reloads from disk. Objects smaller than this threshold
30+
// are now always read into memory and stored in cache instead of being
31+
// wrapped in FSObject.
32+
const smallObjectThreshold = 16 * 1024
33+
2434
// Packfile allows retrieving information from inside a packfile.
2535
type Packfile struct {
2636
idxfile.Index
@@ -208,7 +218,7 @@ func (p *Packfile) objectAtOffset(offset int64) (plumbing.EncodedObject, error)
208218

209219
// If we have no filesystem, we will return a MemoryObject instead
210220
// of an FSObject.
211-
if p.fs == nil || h.Length <= 16*1024 {
221+
if p.fs == nil || h.Length <= smallObjectThreshold {
212222
return p.getNextObject(h)
213223
}
214224

0 commit comments

Comments
 (0)