Speed up blob sorting in internal/repository

name                    old time/op    new time/op    delta
SortCachedPacksFirst-8     208µs ± 3%     186µs ± 3%  -10.74%  (p=0.000 n=10+8)

name                    old alloc/op   new alloc/op   delta
SortCachedPacksFirst-8     213kB ± 0%     139kB ± 0%  -34.62%  (p=0.000 n=10+10)

name                    old allocs/op  new allocs/op  delta
SortCachedPacksFirst-8     1.03k ± 0%     1.03k ± 0%   -0.19%  (p=0.000 n=10+10)
This commit is contained in:
greatroar 2020-03-06 09:18:38 +01:00 committed by Michael Eischer
parent b10acd2af7
commit 03d23e6faa
1 changed files with 2 additions and 1 deletions

View File

@ -116,6 +116,7 @@ type haver interface {
}
// sortCachedPacksFirst moves all cached pack files to the front of blobs.
// It overwrites blobs.
func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) []restic.PackedBlob {
if cache == nil {
return blobs
@ -126,7 +127,7 @@ func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) []restic.Packe
return blobs
}
cached := make([]restic.PackedBlob, 0, len(blobs)/2)
cached := blobs[:0]
noncached := make([]restic.PackedBlob, 0, len(blobs)/2)
for _, blob := range blobs {