Skip to content

Fix full-width runs in batched bitmap iteration - #402

Closed
perfloop-agent wants to merge 1 commit into
RoaringBitmap:mainfrom
perfloop-oss:perfloop-pr-open-g4sk51crja
Closed

perfloop-agent wants to merge 1 commit into
RoaringBitmap:mainfrom
perfloop-oss:perfloop-pr-open-g4sk51crja

Conversation

@perfloop-agent

Copy link
Copy Markdown

The next_many API added in #346 can panic or silently lose an untouched full-width run. For example, insert_range(0..=65535) creates one run containing 65,536 values. Reading it into a nonempty batch buffer adds one to the run length in u16 before converting to usize. With overflow checks disabled, that count wraps to zero and the run is discarded without returning its values.

Convert the endpoint difference to usize before adding one. This represents the full inclusive count while leaving the existing full-run and partial-run advancement paths intact. The change applies to both borrowed and owned bitmap iteration without changing their public APIs.

The regression in roaring/tests/iter_next_many.rs checks one-slot, just-under-full, exact-fit, and oversized buffers, repeated batches, backward trimming, and exhaustion for both iterator forms.

Cargo’s batch-iteration integration suite passed 13 tests in each of the default-with-serde, no-default-features, and overflow-checks-disabled configurations, with no failures or skips. Formatting and Clippy checks passed for the affected package.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart. To ask for a change, comment or review in plain words. How Perfloop handles pull requests.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Tomás Senart <ts@perfloop.ai>
@tsenart

tsenart commented Nov 9, 2026

Copy link
Copy Markdown

Hi @Kerollmops, I'm Tomás Senart, the human sponsor for this contribution. Perfloop made this change under my sponsorship, and I reviewed the patch and its test evidence before bringing it here.

This fixes a correctness problem in batched iteration, not a claimed speedup. A full run contains 65,536 values, but its inclusive length is calculated in u16. That can panic with overflow checks enabled or return no values for that run when checks are disabled. The change widens the difference before adding one, and the regression covers borrowed and owned iterators with several buffer sizes and backward trimming.

I'd welcome feedback in plain words, whether it is about the code, the tests, or how this contribution is presented. If something does not fit the project, please say what you would prefer. I will take responsibility for the response and review any follow-up changes. There is no need to learn a special command or use another service to ask for a change. Thanks for taking a look.

@Kerollmops Kerollmops closed this Nov 9, 2026
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.

3 participants