Skip to content

Avoid bitmap conversions in non-inplace array subtraction - #555

Merged
lemire merged 3 commits into
RoaringBitmap:masterfrom
perfloop:perfloop-pr-open-r8sx8khc5v
Aug 24, 2026
Merged

Avoid bitmap conversions in non-inplace array subtraction#555
lemire merged 3 commits into
RoaringBitmap:masterfrom
perfloop:perfloop-pr-open-r8sx8khc5v

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Description

Avoid bitmap-container conversion when subtracting runs from an array container in non-inplace AndNot operations. The result keeps the existing array representation and input ownership.

Workload: BenchmarkAndNotArrayArray

Metric Before After Change
ns/op 5689 1342 76.4% lower
Checks: 2 passed.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement
  • Code refactoring
  • Documentation update
  • Test improvements
  • Build/CI changes

Changes Made

What was changed?

  • Handle a single run by copying the array portions outside the interval.
  • Handle multiple runs by cloning the array and using the existing in-place subtraction.
  • Reuse interval subtraction for contiguous array operands and keep difference for other arrays.

Why was it changed?

  • The previous non-inplace array/run path allocated and scanned bitmap containers unnecessarily.

How was it changed?

  • Added a shared interval subtraction helper without changing input ownership.
  • Added 32-bit and 64-bit correctness coverage and focused benchmarks.

Testing

  • go test -count=1 ./...

Formatting

  • gofmt -s cleanliness check passed for the changed Go files.

Fuzzing

  • go test -tags=gofuzz -run=TestGenerateSmatCorpus ./...
  • go test -tags=gofuzz -run=TestSmatHits ./...

Performance Impact

  • Single-interval array subtraction avoids bitmap buffers and uses two searches plus prefix/suffix copies.
  • Multi-interval subtraction keeps the existing in-place run algorithm on a cloned array.
  • Non-contiguous array operands retain the existing difference path.

Breaking Changes

None.

Related Issues

None.

Additional Notes

The focused tests also verify result boundaries and that non-inplace operations leave both inputs unchanged.


Generated by Perfloop. Measurements and checks.

@lemire

lemire commented Aug 24, 2026

Copy link
Copy Markdown
Member

Very good.

@lemire
lemire merged commit 33d5fbf into RoaringBitmap:master Aug 24, 2026
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