Repository navigation
Redis native compressed bitmaps (redis-roaring) - #15331
Merged
Merged
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This was referenced Jun 11, 2026
sundb
reviewed
Jun 12, 2026
sundb
requested changes
Jun 12, 2026
This comment was marked as resolved.
This comment was marked as resolved.
sundb
reviewed
Jun 12, 2026
sundb
requested changes
Jun 12, 2026
sundb
reviewed
Jun 14, 2026
sundb
reviewed
Jun 15, 2026
sundb
reviewed
Jun 15, 2026
sundb
reviewed
Jun 15, 2026
sundb
reviewed
Jun 17, 2026
This was referenced Jun 17, 2026
sundb
requested changes
Jun 18, 2026
sundb
reviewed
Jun 18, 2026
sundb
reviewed
Jun 18, 2026
sundb
requested changes
Jun 22, 2026
sundb
requested changes
Jun 22, 2026
sundb
self-requested a review
June 22, 2026 05:03
commented
Oct 13, 2026
Contributor
Author
|
@sundb Could you please re-review the latest changes? The remaining October 12 feedback is addressed, the upstream conflict is resolved, and the CLA check now passes. The feedback changes remain in separate commits. |
commented
Oct 13, 2026
Collaborator
sundb
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15296
Native Roaring bitmaps
Adds a native Roaring bitmap representation for Redis bitmaps, backed by vendored CRoaring v4.7.2 (
deps/croaring, built with SIMD disabled and symbols hidden for portability). A string bitmap costs one byte per 8 bit positions up to its highest offset, regardless of how many bits are set; sparse or large bitmaps are instead stored compressed, cutting memory dramatically while preserving exact bit semantics.Type & object model
OBJ_BITMAPwith encodingOBJ_ENCODING_BITMAP_ROARING.TYPE→bitmap,OBJECT ENCODING→bitmap-roaring.encodingwidened 4→5 bits to fit the new encoding value; to keepredisObjectthe same width,refcountdrops 23→22 bits, lowering the maximum non-shared refcount from 8388605 to 4194301 (still far above any real per-object refcount).Enabling it —
bitmap-default-roaringBITOPwith a Roaring source,RESTORE, replication, or loading an RDB/AOF containing them.BITOPdestinations are Roaring. Automatic creation/conversion is disabled on replicas and when a write's propagation excludes either AOF or replicas — notablyRM_Call()without!, selectiveRM_Call()flags, and scripts usingredis.set_repl(); such writes keep plain strings on every node.Command surface & string boundary
SETBIT,GETBIT,BITCOUNT,BITPOS,BITOP,BITFIELD,BITFIELD_RO.GET,GETRANGE,APPEND,SETRANGE,STRLEN, …) returnWRONGTYPE.DEBUG BITMAP-RAWexposes the materialized bytes.proto-max-bulk-len× 8. Internal representability is bounded at 2^60−1 logical bytes (BITROAR_MAX_BYTES).BITOP NOTover a Roaring source bounds missing-chunk allocation with a budget derived fromproto-max-bulk-len(minimum 65,536 chunks of 8 KiB). Replication and AOF replay bypass this budget to apply accepted operations; dense string sources are exempt.Persistence
RDB_TYPE_BITMAP(33) under the existing RDB version 16 introduced for 8.12 (this PR does not bump it). This relies on shipping in 8.12: 8.12 milestone builds without this PR reject type 33 cleanly, and if the PR slips past 8.12,RDB_VERSIONmust be bumped. The RDB/DUMP payload is the logical byte length followed by the CRoaring64 portable serialization — compact, not a dense byte expansion. Loading enforces the representability bound and validates the blob.Replication & AOF — deterministic by construction
BITCONVERT <key>andBITROAROPcommands (hidden fromCOMMAND, internal-client gated,since 8.12.0;ACL CATandACL DRYRUNare not yet filtered and still list them):SETBIT/BITFIELDcreating or converting a bitmap replay asBITCONVERTfollowed by the original command, grouped inMULTI/EXEC;BITOPwhose destination is Roaring only by configuration replays as internalBITROAROP, which stores the native result directly and preserves notification and callback ordering;BITCONVERTapplies the same in-place transition the primary performed: TTL and module metadata retained, no value payload in the stream.Notifications, modules, cluster
NOTIFY_BITMAP(classb) keyspace events; conversion is an observable in-place type change:type_changed(classc) then the command's own event when it changes the logical value — neveroverwritten. A conversion that leaves the logical value unchanged still emitstype_changed, counts as a write, and is propagated. A newly created native key emitsnew(classn) rather thantype_changed.REDISMODULE_KEYTYPE_BITMAPadded.tests/unit/cluster/bitmap.tcl,atomic-slot-migration.tclcoverage).Memory accounting & active defrag
zmalloc. Active defrag walks the Roaring64 ART and its ARRAY, BITSET, and RUN containers (via a small vendor patch exposingroaring64internals), and fork-child memory is dismissed correctly. INFO keysizes gains adistrib_bitmaps_sizeshistogram of logical byte length, not memory: a sparse Roaring bitmap can be orders of magnitude smaller than its bucket, unlikedistrib_<collection>_sizes, which reports allocation size. Bitmap allocation sizes are tracked internally but, as for strings, not reported by INFO.Testing
tests/unit/bitroar.tcl(encoding, conversion, RDB/AOF/replication determinism incl. mode-mismatch masters/replicas, defrag, module boundary), string↔Roaring parity oracle cases in the same suite, plus additions tobitops.tcl,memefficiency.tcl,corrupt-dump-fuzzer.tcl,info-keysizes.tcl,integration/replication-3.tcl,integration/dismiss-mem.tcl, cluster suites,moduleapi/keyspace_eventstransition-callback replay coverage, andmoduleapi/propagateselective-propagation coverage.Documentation
Note
Medium Risk
Adds a large vendored dependency with local patches to internal 64-bit layout; incorrect integration could affect build portability and future memory/defrag paths that walk CRoaring allocations.
Overview
Vendors CRoaring v4.7.2 under
deps/croaringas the C Roaring bitmap engine for Redis’s native compressed bitmap encodings, with upstream sources plus Redis-maintained build/docs (not upstream CMake).Build integration:
deps/Makefilegains acroaringtarget that produceslibroaring.awith hidden symbol visibility, x64 SIMD and NEON disabled (ROARING_DISABLE_X64,DISABLENEON), and LTO not inherited from Redis so CI/cross-builds stay linkable.distcleanand.gitignorecover the new archive;ARisAR?=so cross-compile toolchains can override the archiver.Redis-specific maintenance:
deps/README.mddocuments upgrade steps, local patches (portability/endian/atomics inportability.h, and 64-bit internal layout exposure forbitroarmemory accounting, fork-child dismissal, and active defrag), and a small refcount-none regression test in the croaring Makefile.Reviewed by Cursor Bugbot for commit 8963e1c. Bugbot is set up for automated code reviews on this repo. Configure here.