Skip to content

Commit e8256d3

Browse files
RaduBerindelemire
authored andcommitted
Always use uint8 for t2count and reverseH in buildBinaryFuse
The values stored in these slices are independent of the fingerprint size. It looks like maybe a mistake when the code was converted to use generics. This improves build performance a bit (and reduces mem usage) for 16-bit fingerprints. On an M1 laptop: ``` name old time/op new time/op delta BinaryFusePopulate/16/n=1000000-10 29.4ms ± 1% 28.1ms ± 1% -4.25% (p=0.000 n=10+10) name old MKeys/s new MKeys/s delta BinaryFusePopulate/16/n=1000000-10 34.1 ± 1% 35.6 ± 1% +4.44% (p=0.000 n=10+10) name old alloc/op new alloc/op delta BinaryFusePopulate/16/n=1000000-10 28.1MB ± 0% 26.0MB ± 0% -7.58% (p=0.000 n=8+9) name old allocs/op new allocs/op delta BinaryFusePopulate/16/n=1000000-10 8.00 ± 0% 8.00 ± 0% ~ (all equal) ```
1 parent 9e0c9da commit e8256d3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

binaryfusefilter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func buildBinaryFuse[T Unsigned](b *BinaryFuseBuilder, keys []uint64) (_ BinaryF
7272
// the lowest 2 bits are the h index (0, 1, or 2)
7373
// so we only have 6 bits for counting;
7474
// but that's sufficient
75-
t2count := reuseBuffer[T](&b.t2count, int(capacity))
76-
reverseH := reuseBuffer[T](&b.reverseH, int(size))
75+
t2count := reuseBuffer[uint8](&b.t2count, int(capacity))
76+
reverseH := reuseBuffer[uint8](&b.reverseH, int(size))
7777

7878
t2hash := reuseBuffer[uint64](&b.t2hash, int(capacity))
7979
reverseOrder := reuseBuffer[uint64](&b.reverseOrder, int(size+1))
@@ -297,7 +297,7 @@ func (filter *BinaryFuse[T]) initializeParameters(b *BinaryFuseBuilder, size uin
297297
filter.Fingerprints = reuseBuffer[T](&b.fingerprints, int(arrayLength))
298298
}
299299

300-
func (filter *BinaryFuse[T]) mod3(x T) T {
300+
func (filter *BinaryFuse[T]) mod3(x uint8) uint8 {
301301
if x > 2 {
302302
x -= 3
303303
}

0 commit comments

Comments
 (0)