Skip to content

Commit 60bc550

Browse files
authored
Merge pull request #515 from anacrolix/bsi-clearvalues-serial
BSI: fix ClearValues being slower than a serial loop
2 parents b4a7332 + e5faa9e commit 60bc550

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

roaring64/bsi64.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -971,23 +971,18 @@ func ClearBits(foundSet, target *Bitmap) {
971971
target.AndNot(foundSet)
972972
}
973973

974-
// ClearValues removes the values found in foundSet
974+
// ClearValues removes from the BSI all values whose column IDs are in
975+
// foundSet, modifying the BSI in place.
976+
//
977+
// The implementation is intentionally serial. A previous goroutine-per-bit-plane
978+
// approach was slower in practice: goroutine creation overhead dominated for
979+
// typical BSI sizes, and the cost compounds when ClearValues is called in a
980+
// tight loop (e.g. once per term across an entire index during a deletion pass).
975981
func (b *BSI) ClearValues(foundSet *Bitmap) {
976-
977-
var wg sync.WaitGroup
978-
wg.Add(1)
979-
go func() {
980-
defer wg.Done()
981-
b.eBM.AndNot(foundSet)
982-
}()
983-
for i := 0; i < b.BitCount(); i++ {
984-
wg.Add(1)
985-
go func(j int) {
986-
defer wg.Done()
987-
b.bA[j].AndNot(foundSet)
988-
}(i)
982+
b.eBM.AndNot(foundSet)
983+
for i := range b.bA {
984+
b.bA[i].AndNot(foundSet)
989985
}
990-
wg.Wait()
991986
}
992987

993988
// NewBSIRetainSet - Construct a new BSI from a clone of existing BSI, retain only values contained in foundSet

0 commit comments

Comments
 (0)