mirror of
https://github.com/restic/restic.git
synced 2025-12-04 03:38:25 +00:00
repository: optimize MasterIndex.Each
Sending data through a channel at very high frequency is extremely inefficient. Thus use simple callbacks instead of channels. > name old time/op new time/op delta > MasterIndexEach-16 6.68s ±24% 0.96s ± 2% -85.64% (p=0.008 n=5+5)
This commit is contained in:
@@ -163,9 +163,9 @@ func TestMasterMergeFinalIndexes(t *testing.T) {
|
||||
rtest.Equals(t, 1, idxCount)
|
||||
|
||||
blobCount := 0
|
||||
for range mIdx.Each(context.TODO()) {
|
||||
mIdx.Each(context.TODO(), func(pb restic.PackedBlob) {
|
||||
blobCount++
|
||||
}
|
||||
})
|
||||
rtest.Equals(t, 2, blobCount)
|
||||
|
||||
blobs := mIdx.Lookup(bhInIdx1)
|
||||
@@ -195,9 +195,9 @@ func TestMasterMergeFinalIndexes(t *testing.T) {
|
||||
rtest.Equals(t, []restic.PackedBlob{blob2}, blobs)
|
||||
|
||||
blobCount = 0
|
||||
for range mIdx.Each(context.TODO()) {
|
||||
mIdx.Each(context.TODO(), func(pb restic.PackedBlob) {
|
||||
blobCount++
|
||||
}
|
||||
})
|
||||
rtest.Equals(t, 2, blobCount)
|
||||
}
|
||||
|
||||
@@ -316,9 +316,9 @@ func BenchmarkMasterIndexEach(b *testing.B) {
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
entries := 0
|
||||
for _ = range mIdx.Each(context.TODO()) {
|
||||
mIdx.Each(context.TODO(), func(pb restic.PackedBlob) {
|
||||
entries++
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user