forked from TrueCloudLab/restic
Merge pull request #3879 from MichaelEischer/mem-optimize
Some random (minor) memory-allocation optimizations
This commit is contained in:
commit
bee15dd555
3 changed files with 9 additions and 1 deletions
|
@ -294,6 +294,8 @@ func (idx *Index) EachByPack(ctx context.Context, packBlacklist restic.IDSet) <-
|
||||||
result.Blobs = append(result.Blobs, idx.toPackedBlob(e, restic.BlobType(typ)).Blob)
|
result.Blobs = append(result.Blobs, idx.toPackedBlob(e, restic.BlobType(typ)).Blob)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// allow GC once entry is no longer necessary
|
||||||
|
byPack[packID] = nil
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
|
@ -52,6 +52,10 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
|
||||||
var idx *Index
|
var idx *Index
|
||||||
oldFormat := false
|
oldFormat := false
|
||||||
|
|
||||||
|
if cap(buf) < int(fi.Size) {
|
||||||
|
// overallocate a bit
|
||||||
|
buf = make([]byte, fi.Size+128*1024)
|
||||||
|
}
|
||||||
buf, err = repo.LoadUnpacked(ctx, restic.IndexFile, fi.ID, buf[:0])
|
buf, err = repo.LoadUnpacked(ctx, restic.IndexFile, fi.ID, buf[:0])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
idx, oldFormat, err = DecodeIndex(buf, fi.ID)
|
idx, oldFormat, err = DecodeIndex(buf, fi.ID)
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (mi *MasterIndex) Packs(packBlacklist restic.IDSet) restic.IDSet {
|
||||||
packs := restic.NewIDSet()
|
packs := restic.NewIDSet()
|
||||||
for _, idx := range mi.idx {
|
for _, idx := range mi.idx {
|
||||||
idxPacks := idx.Packs()
|
idxPacks := idx.Packs()
|
||||||
if idx.final {
|
if idx.final && len(packBlacklist) > 0 {
|
||||||
idxPacks = idxPacks.Sub(packBlacklist)
|
idxPacks = idxPacks.Sub(packBlacklist)
|
||||||
}
|
}
|
||||||
packs.Merge(idxPacks)
|
packs.Merge(idxPacks)
|
||||||
|
@ -458,6 +458,8 @@ func (mi *MasterIndex) ListPacks(ctx context.Context, packs restic.IDSet) <-chan
|
||||||
|
|
||||||
// pass on packs
|
// pass on packs
|
||||||
for packID, pbs := range packBlob {
|
for packID, pbs := range packBlob {
|
||||||
|
// allow GC
|
||||||
|
packBlob[packID] = nil
|
||||||
select {
|
select {
|
||||||
case out <- restic.PackBlobs{PackID: packID, Blobs: pbs}:
|
case out <- restic.PackBlobs{PackID: packID, Blobs: pbs}:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
Loading…
Reference in a new issue