From 962eeb399ce322daa4dd6522cdc91d277fbdba2c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 20 Dec 2017 15:11:38 +0100 Subject: Enforce the use of cache in packfile decoder Decoder object can make use of an object cache to speed up processing. Previously the only way to specify it was changing manually the struct generated by NewDecodeForFile. This lead to some instances to be created without it and penalized performance. Now the cache should be explicitly passed to the constructor function. NewDecoder now creates objects with a cache using the default size. A new helper function was added to create cache objects with the default size as this becomes a common task now: cache.NewObjectLRUDefault() Signed-off-by: Javi Fontan --- storage/filesystem/object.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'storage/filesystem/object.go') diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index fd52ed5..9c5ca21 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -18,8 +18,6 @@ import ( "gopkg.in/src-d/go-billy.v4" ) -const DefaultMaxDeltaBaseCacheSize = 92 * cache.MiByte - type ObjectStorage struct { // DeltaBaseCache is an object cache uses to cache delta's bases when DeltaBaseCache cache.Object @@ -30,7 +28,7 @@ type ObjectStorage struct { func newObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { s := ObjectStorage{ - DeltaBaseCache: cache.NewObjectLRU(DefaultMaxDeltaBaseCacheSize), + DeltaBaseCache: cache.NewObjectLRUDefault(), dir: dir, } @@ -433,13 +431,12 @@ func newPackfileIter(f billy.File, t plumbing.ObjectType, seen map[plumbing.Hash return nil, err } - d, err := packfile.NewDecoderForType(s, memory.NewStorage(), t) + d, err := packfile.NewDecoderForType(s, memory.NewStorage(), t, cache) if err != nil { return nil, err } d.SetIndex(index) - d.DeltaBaseCache = cache return &packfileIter{ f: f, -- cgit From 8f82387beb7ae4ac8936d893f58c6a29992a7050 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 20 Dec 2017 16:39:45 +0100 Subject: Make DeltaBaseCache private Signed-off-by: Javi Fontan --- storage/filesystem/object.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'storage/filesystem/object.go') diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 9c5ca21..3ec7304 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -19,8 +19,8 @@ import ( ) type ObjectStorage struct { - // DeltaBaseCache is an object cache uses to cache delta's bases when - DeltaBaseCache cache.Object + // deltaBaseCache is an object cache uses to cache delta's bases when + deltaBaseCache cache.Object dir *dotgit.DotGit index map[plumbing.Hash]*packfile.Index @@ -28,7 +28,7 @@ type ObjectStorage struct { func newObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { s := ObjectStorage{ - DeltaBaseCache: cache.NewObjectLRUDefault(), + deltaBaseCache: cache.NewObjectLRUDefault(), dir: dir, } @@ -285,13 +285,13 @@ func (s *ObjectStorage) decodeObjectAt( p := packfile.NewScanner(f) - d, err := packfile.NewDecoder(p, memory.NewStorage()) + d, err := packfile.NewDecoderWithCache(p, memory.NewStorage(), + s.deltaBaseCache) if err != nil { return nil, err } d.SetIndex(idx) - d.DeltaBaseCache = s.DeltaBaseCache obj, err := d.DecodeObjectAt(offset) return obj, err } @@ -398,7 +398,7 @@ func (s *ObjectStorage) buildPackfileIters(t plumbing.ObjectType, seen map[plumb return nil, err } - iter, err := newPackfileIter(pack, t, seen, s.index[h], s.DeltaBaseCache) + iter, err := newPackfileIter(pack, t, seen, s.index[h], s.deltaBaseCache) if err != nil { return nil, err } -- cgit