Skip to content

BSI: fix ClearValues being slower than a serial loop#515

Merged
lemire merged 2 commits intoRoaringBitmap:masterfrom
anacrolix:bsi-clearvalues-serial
Mar 9, 2026
Merged

BSI: fix ClearValues being slower than a serial loop#515
lemire merged 2 commits intoRoaringBitmap:masterfrom
anacrolix:bsi-clearvalues-serial

Conversation

@anacrolix
Copy link
Contributor

Summary

ClearValues previously spawned one goroutine per bit plane plus one for
the existence bitmap on every call. The goroutine creation overhead
dominated for typical BSI sizes, making the function slower than a simple
serial loop — in practice, an order of magnitude or more.

The fix replaces the parallel implementation with a straightforward serial
loop. The performance case for parallelism doesn't hold here: the work per
bit plane is a single AndNot on an already-vectorized bitmap, which
completes faster than the goroutine scheduler can dispatch. The cost also
compounds when ClearValues is called in a tight loop, such as once per
term when purging deleted documents from an entire index.

The goroutine-per-bit-plane approach it replaced was slower in practice.
Goroutine creation overhead dominates for typical BSI sizes, and the cost
compounds when ClearValues is called once per term in a deletion pass over
an entire index (the pattern used in caterwaul's DeleteGroups).
@anacrolix anacrolix marked this pull request as ready for review March 9, 2026 11:15
@lemire lemire merged commit 60bc550 into RoaringBitmap:master Mar 9, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants