From 2e2905e4bb882647c0f9ae019d59e6c36a3a1821 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Tue, 13 Jan 2026 13:54:10 -0800 Subject: [PATCH] Always use uint8 for t2count and reverseH in buildBinaryFuse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) ``` --- binaryfusefilter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binaryfusefilter.go b/binaryfusefilter.go index 6c4b029..f7093b0 100644 --- a/binaryfusefilter.go +++ b/binaryfusefilter.go @@ -72,8 +72,8 @@ func buildBinaryFuse[T Unsigned](b *BinaryFuseBuilder, keys []uint64) (_ BinaryF // the lowest 2 bits are the h index (0, 1, or 2) // so we only have 6 bits for counting; // but that's sufficient - t2count := reuseBuffer[T](&b.t2count, int(capacity)) - reverseH := reuseBuffer[T](&b.reverseH, int(size)) + t2count := reuseBuffer[uint8](&b.t2count, int(capacity)) + reverseH := reuseBuffer[uint8](&b.reverseH, int(size)) t2hash := reuseBuffer[uint64](&b.t2hash, int(capacity)) reverseOrder := reuseBuffer[uint64](&b.reverseOrder, int(size+1)) @@ -297,7 +297,7 @@ func (filter *BinaryFuse[T]) initializeParameters(b *BinaryFuseBuilder, size uin filter.Fingerprints = reuseBuffer[T](&b.fingerprints, int(arrayLength)) } -func (filter *BinaryFuse[T]) mod3(x T) T { +func (filter *BinaryFuse[T]) mod3(x uint8) uint8 { if x > 2 { x -= 3 }