Improve performance of simple reflist merges

When merging reflists with ignoreConflicting set to true and
overrideMatching set to false, the individual ref components are never
examined, but the refs are still split anyway. Avoiding the split when
we never use the components brings a massive speedup: on my system, the
included benchmark goes from ~1500 us/it to ~180 us/it.

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
This commit is contained in:
Ryan Gonzalez
2023-09-13 10:41:00 -05:00
committed by André Roth
parent 8ab8398c50
commit 5636a9990b
2 changed files with 58 additions and 25 deletions
+30
View File
@@ -0,0 +1,30 @@
package deb
import (
"fmt"
"sort"
"testing"
)
func BenchmarkReflistSimpleMerge(b *testing.B) {
const count = 4096
l := NewPackageRefList()
r := NewPackageRefList()
for i := 0; i < count; i++ {
if i%2 == 0 {
l.Refs = append(l.Refs, []byte(fmt.Sprintf("Pamd64 pkg%d %d", i, i)))
} else {
r.Refs = append(r.Refs, []byte(fmt.Sprintf("Pamd64 pkg%d %d", i, i)))
}
}
sort.Sort(l)
sort.Sort(r)
b.ResetTimer()
for i := 0; i < b.N; i++ {
l.Merge(r, false, true)
}
}