2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

index: let indexmap.Each iterate in allocation order

Iterating through the indexmap according to the bucket order has the
problem that all indexEntries are accessed in random order which is
rather cache inefficient.

As we already keep a list of all allocated blocks, just iterate through
it. This allows iterating through a batch of indexEntries without random
memory accesses. In addition, the packID will likely remain similar
across multiple blobs as all blobs of a pack file are added as a single
batch.
This commit is contained in:
Michael Eischer 2023-05-30 20:12:36 +02:00
parent f1c388c623
commit fc05e35a08

View File

@ -54,13 +54,10 @@ func (m *indexMap) add(id restic.ID, packIdx int, offset, length uint32, uncompr
// foreach calls fn for all entries in the map, until fn returns false. // foreach calls fn for all entries in the map, until fn returns false.
func (m *indexMap) foreach(fn func(*indexEntry) bool) { func (m *indexMap) foreach(fn func(*indexEntry) bool) {
for _, ei := range m.buckets { blockCount := m.blockList.Size()
for ei != 0 { for i := uint(1); i < blockCount; i++ {
e := m.resolve(ei) if !fn(m.resolve(i)) {
if !fn(e) { return
return
}
ei = e.next
} }
} }
} }