Skip to content

Commit c90bca4

Browse files
committed
feature: introduces FillUp method
1 parent 37d88a0 commit c90bca4

5 files changed

+1371
-59
lines changed

benchmark_opt_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,51 @@ func BenchmarkPrefillFromSortedList(b *testing.B) {
3232
}
3333
}
3434

35+
// go test -v -bench BenchmarkFillUpNative -benchmem -run ^$ github.com/weaviate/sroar -cpuprofile cpu.prof
36+
func BenchmarkFillUpNative(b *testing.B) {
37+
for i := 0; i < b.N; i++ {
38+
bm := Prefill(100_000_000)
39+
bm.FillUp(150_000_000)
40+
bm.FillUp(200_000_000)
41+
}
42+
}
43+
44+
// go test -v -bench BenchmarkPrefillFromSortedList -benchmem -run ^$ github.com/weaviate/sroar -cpuprofile cpu.prof
45+
func BenchmarkFillUpFromSortedList(b *testing.B) {
46+
prefillBufferSize := 65_536
47+
maxVal1 := uint64(100_000_000)
48+
maxVal2 := uint64(150_000_000)
49+
maxVal3 := uint64(200_000_000)
50+
inc := uint64(prefillBufferSize)
51+
buf := make([]uint64, prefillBufferSize)
52+
53+
for i := 0; i < b.N; i++ {
54+
finalBM := NewBitmap()
55+
56+
for i := uint64(0); i <= maxVal1; i += inc {
57+
j := uint64(0)
58+
for ; j < inc && i+j <= maxVal1; j++ {
59+
buf[j] = i + j
60+
}
61+
finalBM.Or(FromSortedList(buf[:j]))
62+
}
63+
for i := maxVal1 + 1; i <= maxVal2; i += inc {
64+
j := uint64(0)
65+
for ; j < inc && i+j <= maxVal2; j++ {
66+
buf[j] = i + j
67+
}
68+
finalBM.Or(FromSortedList(buf[:j]))
69+
}
70+
for i := maxVal2 + 1; i <= maxVal3; i += inc {
71+
j := uint64(0)
72+
for ; j < inc && i+j <= maxVal3; j++ {
73+
buf[j] = i + j
74+
}
75+
finalBM.Or(FromSortedList(buf[:j]))
76+
}
77+
}
78+
}
79+
3580
// ================================================================================
3681
//
3782
// BENCHMARKS comparing performance of different merge implementations

bitmap.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ func newBitampToBuf(keysLen, initialContainerSize int, buf []uint16) *Bitmap {
115115
ra := &Bitmap{data: buf[:keysLen]}
116116
ra.keys = toUint64Slice(ra.data)
117117
ra.keys.setNodeSize(keysLen)
118-
119118
// Always generate a container for key = 0x00. Otherwise, node gets confused
120119
// about whether a zero key is a new key or not.
121120
offset := ra.newContainer(uint16(initialContainerSize))
@@ -244,9 +243,14 @@ func (ra *Bitmap) scootLeft(offset uint64, size uint64) {
244243
}
245244

246245
func (ra *Bitmap) newContainer(sz uint16) uint64 {
246+
// fmt.Printf(" ==> newContainer sz [%d]\n", sz)
247247
offset := ra.newContainerNoClr(sz)
248+
// fmt.Printf(" ==> newContainer offset [%d]\n", offset)
248249
ra.data[offset] = sz
250+
// fmt.Printf(" ==> newContainer ra.data[offset] [%d]\n", ra.data[offset])
249251
Memclr(ra.data[offset+1 : offset+uint64(sz)])
252+
// fmt.Printf(" ==> newContainer ra.data[offset] [%d]\n", ra.data[offset])
253+
250254
return offset
251255
}
252256

0 commit comments

Comments
 (0)