From b3fc7760ba332306bb1faa64c8a101a2e605077f Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 24 Jul 2017 14:04:51 +0200 Subject: storage/filesystem: reuse delta cache Reuse delta base object cache for packfile decoders across multiple instances. --- storage/filesystem/object.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'storage/filesystem') diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index e235b33..4a67a00 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -5,6 +5,7 @@ import ( "os" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/cache" "gopkg.in/src-d/go-git.v4/plumbing/format/idxfile" "gopkg.in/src-d/go-git.v4/plumbing/format/objfile" "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" @@ -16,14 +17,20 @@ import ( "gopkg.in/src-d/go-billy.v3" ) +const DefaultMaxDeltaBaseCacheSize = 92 * cache.MiByte + type ObjectStorage struct { + // DeltaBaseCache is an object cache uses to cache delta's bases when + DeltaBaseCache cache.Object + dir *dotgit.DotGit index map[plumbing.Hash]*packfile.Index } func newObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { s := ObjectStorage{ - dir: dir, + DeltaBaseCache: cache.NewObjectFIFO(DefaultMaxDeltaBaseCacheSize), + dir: dir, } return s, nil @@ -198,6 +205,7 @@ func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.EncodedObject return nil, err } + d.DeltaBaseCache = s.DeltaBaseCache d.SetIndex(s.index[pack]) obj, err := d.DecodeObjectAt(offset) return obj, err -- cgit From ae1c4f3df729c3a7fed4cd5a1f530c95d640497a Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 24 Jul 2017 14:19:21 +0200 Subject: plumbing/cache: change FIFO to LRU cache --- storage/filesystem/object.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'storage/filesystem') diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 4a67a00..6dd910b 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -29,7 +29,7 @@ type ObjectStorage struct { func newObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) { s := ObjectStorage{ - DeltaBaseCache: cache.NewObjectFIFO(DefaultMaxDeltaBaseCacheSize), + DeltaBaseCache: cache.NewObjectLRU(DefaultMaxDeltaBaseCacheSize), dir: dir, } -- cgit