From 3f6c17f4338996f28d65b3c51d20ad217d5cc8f0 Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 26 Nov 2018 13:10:26 -0600 Subject: [PATCH] roaring: use DirectAdd rather than op.apply for cheap performance win MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling op.apply on an op we know to be an add ends up noticably increasing the cost of the operation; this trivial change gets about a 5-10% reduction in reported runtime of benchmarks doing a lot of adds. (The other IntersectionCount benchmarks don't actually use Add most of the time, so it doesn't show up in them.) name old time/op new time/op delta GetBenchData-8 4.25ms ± 0% 3.91ms ± 2% -8.04% (p=0.002 n=6+6) Bitmap_IntersectionCount_ArrayArray-8 20.9µs ± 2% 18.7µs ± 3% -10.18% (p=0.004 n=5+6) SliceAscending-8 24.7ms ± 0% 21.8ms ± 0% -11.74% (p=0.004 n=5+6) SliceDescending-8 29.8ms ± 0% 27.0ms ± 0% -9.56% (p=0.004 n=5+6) SliceAscendingStriped-8 32.0ms ± 0% 29.5ms ± 0% -8.07% (p=0.008 n=5+5) SliceDescendingStriped-8 39.3ms ± 1% 36.8ms ± 1% -6.27% (p=0.002 n=6+6) --- roaring/roaring.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 9c4274df9..c0d4cb996 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -159,9 +159,8 @@ func (b *Bitmap) Add(a ...uint64) (changed bool, err error) { } // Apply to the in-memory bitmap. - if op.apply(b) { + if b.DirectAdd(v) { changed = true - } }