Skip to content

Speed up try_push and insert for increasing values - #405

Open
harismuzaffer wants to merge 4 commits into
RoaringBitmap:mainfrom
harismuzaffer:fix-390-slow-incremental-sorted-insertion
Open

harismuzaffer wants to merge 4 commits into
RoaringBitmap:mainfrom
harismuzaffer:fix-390-slow-incremental-sorted-insertion

Conversation

@harismuzaffer

Copy link
Copy Markdown

Fixes #390

Adds a new field h to BitmapStore. This is the index of the highest non-zero word. It could be little too high because only insertions raise it, removals don't update h - this also means h can never be too low.

This will minimize the scans in max() which currently always starts at 1023 word

New bechmarks are added and here is the summary of the new bechmarks:

cargo bench -p benchmarks -- "try_push|insert ", comparing against --save-baseline on main.
Machine: , Fedora Linux, x86_64.

Benchmark Before After Change
try_push/dense 0..1M 98.2 ms 6.26 ms −93.6%
try_push/64 step 88.9 µs 84.0 µs −5.5% (noise)
insert 64 step (1M values) 35.9 ms 7.12 ms −80.2%
insert 1 3.49 ns 3.68 ns +5.6%
insert several 53.4 ns 56.0 ns +4.9%
create & insert 1 32.1 ns 33.0 ns +2.7% (noise)
create & insert several 121.5 ns 115.8 ns −4.7% (noise)

insert 1 and insert several only re-insert existing values, so they never take the fast path and pay just its extra compares

@harismuzaffer harismuzaffer changed the title Improve incremental sorted insertion Speed up try_push and insert for increasing values Nov 23, 2026
@harismuzaffer
harismuzaffer force-pushed the fix-390-slow-incremental-sorted-insertion branch from 1302c61 to 41f7ced Compare November 23, 2026 11:08

This branch has not been deployed

No deployments
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.

Slow incremental sorted insertion

1 participant