mirror of
https://github.com/restic/restic.git
synced 2025-08-22 09:17:26 +00:00
repository/master_index: Optimize Index.Lookup()
When looking up a blob in the master index, with several indexes present in the master index, a significant amount of time is spent generating errors for each failed lookup. However, these errors are often used to check if a blob is present, but the contents are not inspected making the overhead of the error not useful. Instead, change Index.Lookup (and Index.LookupSize) to instead return a boolean denoting if the blob was found instead of an error. Also change all the calls to these functions to handle the new function signature. benchmark old ns/op new ns/op delta BenchmarkMasterIndexLookupSingleIndex-6 820 897 +9.39% BenchmarkMasterIndexLookupMultipleIndex-6 12821 2001 -84.39% BenchmarkMasterIndexLookupSingleIndexUnknown-6 5378 492 -90.85% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 17026 1649 -90.31% benchmark old allocs new allocs delta BenchmarkMasterIndexLookupSingleIndex-6 9 9 +0.00% BenchmarkMasterIndexLookupMultipleIndex-6 59 19 -67.80% BenchmarkMasterIndexLookupSingleIndexUnknown-6 22 6 -72.73% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 72 16 -77.78% benchmark old bytes new bytes delta BenchmarkMasterIndexLookupSingleIndex-6 160 160 +0.00% BenchmarkMasterIndexLookupMultipleIndex-6 3200 240 -92.50% BenchmarkMasterIndexLookupSingleIndexUnknown-6 1232 48 -96.10% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 4272 128 -97.00%
This commit is contained in:
@@ -65,8 +65,8 @@ func TestIndexSerialize(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, testBlob := range tests {
|
||||
list, err := idx.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.OK(t, err)
|
||||
list, found := idx.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.Assert(t, found, "Expected to find blob id %v", testBlob.id.Str())
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list)
|
||||
@@ -78,8 +78,8 @@ func TestIndexSerialize(t *testing.T) {
|
||||
rtest.Equals(t, testBlob.offset, result.Offset)
|
||||
rtest.Equals(t, testBlob.length, result.Length)
|
||||
|
||||
list2, err := idx2.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.OK(t, err)
|
||||
list2, found := idx2.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.Assert(t, found, "Expected to find blob id %v", testBlob.id)
|
||||
|
||||
if len(list2) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list2), list2)
|
||||
@@ -146,8 +146,8 @@ func TestIndexSerialize(t *testing.T) {
|
||||
|
||||
// all new blobs must be in the index
|
||||
for _, testBlob := range newtests {
|
||||
list, err := idx3.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.OK(t, err)
|
||||
list, found := idx3.Lookup(testBlob.id, testBlob.tpe)
|
||||
rtest.Assert(t, found, "Expected to find blob id %v", testBlob.id.Str())
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", testBlob.id.Str(), len(list), list)
|
||||
@@ -293,8 +293,8 @@ func TestIndexUnserialize(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, test := range exampleTests {
|
||||
list, err := idx.Lookup(test.id, test.tpe)
|
||||
rtest.OK(t, err)
|
||||
list, found := idx.Lookup(test.id, test.tpe)
|
||||
rtest.Assert(t, found, "Expected to find blob id %v", test.id.Str())
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list)
|
||||
@@ -341,8 +341,8 @@ func TestIndexUnserializeOld(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
|
||||
for _, test := range exampleTests {
|
||||
list, err := idx.Lookup(test.id, test.tpe)
|
||||
rtest.OK(t, err)
|
||||
list, found := idx.Lookup(test.id, test.tpe)
|
||||
rtest.Assert(t, found, "Expected to find blob id %v", test.id.Str())
|
||||
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected one result for blob %v, got %v: %v", test.id.Str(), len(list), list)
|
||||
|
Reference in New Issue
Block a user