{
  "schema_version": 3,
  "id": "develop/data-types/strings/bitmap-intarray-benchmarks",
  "title": "Bitmap integer-array command benchmarks",
  "url": "https://redis.io/docs/latest/develop/data-types/strings/bitmap-intarray-benchmarks/",
  "summary": "Reproduce native bitmap integer-array benchmarks and interpret the historical redis-roaring comparison.",
  "tags": [
    "docs",
    "develop",
    "oss"
  ],
  "last_updated": "2026-11-23T06:19:08-08:00",
  "page_type": "content",
  "content_hash": "1cdac256743e44809648813f5c54868db6dbf13d8ac177ddba4d7410796f68bf",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This guide contains the benchmark methodology and historical measurements\nassociated with [redis/redis#15986](https://github.com/redis/redis/pull/15986).\nThe historical results are retained from that pull request and were measured\nbefore the native commands were renamed and later consolidated into\n`BITRANGEINTARRAY`. They are not measurements of the latest revision.\nSee the [bitmap guide](https://redis.io/docs/latest/develop/data-types/strings/bitmaps)\nfor command usage.\n\nThe benchmark script lives in the Redis source repository at\n[`tools/bitroar-intarray-bench.py`](https://github.com/redis/redis/blob/unstable/tools/bitroar-intarray-bench.py).\nRun the commands below from a Redis checkout that includes `BITRANGEINTARRAY`.\n\n`bitroar-intarray-bench.py` measures `BITRANGEINTARRAY` against\nisolated Redis processes over Unix sockets. It needs Python 3.9+ and a normal\noptimized Redis build; no Python packages or existing server are required.\n\nThe current harness retains the historical `get-all` workload label for\ncomparison files. It invokes `BITRANGEINTARRAY key 0 -1` for a full native\nread, while the reference module uses `R.GETINTARRAY` or `R64.GETINTARRAY`.\nRange workloads select ranks on the module and the equivalent `BIT` offset\ninterval on the native backend, from the first to the last selected offset.\nBoth backends therefore return the same integers.\n\nThe harness measures set-bit reads on native bitmap keys without `LIMIT` or\n`ZEROS`.\nIt does not measure clear-bit enumeration, `LIMIT` pagination, or string scans.\nThe command also reads strings directly within the requested range under either\n`bitmap-default-roaring` setting. No temporary Roaring bitmap is allocated.\nCurrent calls have no fixed result-count cap; client output-buffer limits apply.\nThe historical results do not measure the current implementation.\n\n[code example]\n\nThe optional redis-roaring module baseline runs in a second isolated process.\nPass its Redis binaries via `--module-src-dir`. For a comparison against the\nupstream base, build that revision with the same compiler and flags. The native\n`BIT*` names do not collide with the module's `R.*` names, so this option can also\npoint to the current checkout's `src` directory. The historical measurements\nbelow retain a separate exact-upstream baseline. Pin and record the module\nrevision:\n\n[code example]\n\nWith CMake 4, older dependency minimum versions may require adding\n`-DCMAKE_POLICY_VERSION_MINIMUM=3.5` to the configure command.\n\nThe deterministic datasets include missing keys, dense consecutive runs,\nalternating-bit bitsets, sparse values across 16-bit containers, cardinalities\n16/4096/65536, and sparse values above 2^40. Module comparisons use its `R.*`\ncommands for 32-bit values and `R64.*` for the high-offset dataset. The latter is\nan explicit comparison against the module's 64-bit API, since `R.*` cannot\nrepresent those values.\n\nEvery reply is checked against the expected ascending values before timing.\nWorkloads select the first 16 elements, a middle page containing 1% of the\nelements, the last 16 elements, the whole array, and an empty page beyond the\nlast stored offset. The module receives inclusive element ranks; the native\ncommand receives equivalent bit offset ranges. The same logical data is prepared\nand run-optimized on each backend outside timing. Native setup uses SETBIT and\na DUMP/RESTORE round trip; module setup uses SETINTARRAY and OPTIMIZE MEM.\n\nEach workload is warmed up and measured three times, alternating backend order.\nThe report includes raw redis-benchmark output, every sample, and the median,\nmean, sample standard deviation, minimum and maximum for throughput,\nredis-benchmark latency percentiles and server command execution microseconds.\nIt also records returned element\ncount, and exact RESP2 reply bytes. Request counts are capped by an approximate\n32 MiB reply budget and 0.5-second time budget per trial, with a floor of one\nrequest. The slower backend's initial complete-response validation call bounds\nwarmup to approximately 0.25 seconds or 100 requests. The slower measured warmup\nthroughput then determines the timed request count; both backends use that same\ncount. Validation includes Python response parsing and only provides a fallback\nwhen warmup throughput is invalid or zero (this client reports zero when its\nmillisecond timer cannot resolve the elapsed time). Positive infinity is also\nhandled defensively by retaining only the reply/count caps. Warmup output and\nvalidation times are retained in the JSON. Small\nreplies use up to 5000 requests. Change `--requests`, `--reply-budget-mib`,\n`--trial-seconds`, and `--trials` for longer runs; use `--dataset sparse-65536`\nto select a subset. The JSON records the actual counts. Extremely short trials\ncan fall below redis-benchmark's millisecond throughput timer resolution;\nserver command execution time remains reported separately.\n\nDefault concurrency and pipeline depth are both one. They can be changed with\n`--clients` and `--pipeline`; compare runs with identical settings. Request\ncounts are divisible by the pipeline depth, with at least one full batch even\nwhen that exceeds the nominal budget. The JSON\nrecords CPU affinity, CPU model, cgroup CPU quota, platform, binary hashes,\nmodule revision, and Redis version. Run on an idle machine and retain the JSON\nwith the source revision and compiler/build options used.\n\nThroughput includes consuming the complete response with redis-benchmark's C\nclient. Its latency measurements stop on the first socket read and therefore\nmust not be described as full-array end-to-end latency. Server execution time\ncomes from INFO commandstats deltas and excludes transport/client parsing.\nLarge-array throughput naturally includes reply serialization, buffering, and\nnetwork/client costs; small-page throughput can be limited by round-trip\noverhead. These measurements are diagnostic results, not CI pass/fail gates."
    },
    {
      "id": "historical-measured-comparison-before-the-command-rename-and-consolidation-2026-10-15",
      "title": "Historical measured comparison before the command rename and consolidation (2026-10-15)",
      "role": "content",
      "text": "These measurements used two native commands named `R.GETINTARRAY` and\n`R.RANGEINTARRAY`. They were subsequently renamed to `BITGETINTARRAY` and\n`BITRANGEINTARRAY`, then consolidated into `BITRANGEINTARRAY` with `end = -1`\nfor unbounded reads. No full timing run was repeated for the rename or the\nconsolidation: the source revisions, binary hashes, raw command names, and\nresults below describe the original run. The reference module continues to\nuse its separate `GETINTARRAY` and `RANGEINTARRAY` commands under the `R.*` /\n`R64.*` prefixes.\n\nThis run measured all 50 workloads against both implementations, with three\ntrials per backend. Full replies and exact command counts passed validation.\nResults below describe this machine and these optimized, preloaded datasets;\nthey are not a general speedup claim.\n\nThe native tested source was `7b44c6a975cae96eb806099f99165f63a2489d24`;\nthe unmodified baseline Redis source was\n`4e4c65bc71dd63c1d2dbe999b3d3d86d49772cc5`. Both used GCC 14.2.0,\n`BUILD_TLS=yes REDIS_CFLAGS=-Werror`, Redis's default `-O3`/LTO optimization,\nand jemalloc 5.3.0. The pinned module was\n`e7382b7cea1ec495304e8aa60916c49673e74c1d`, built with CMake Release and\n`ROARING_BUILD_STATIC=ON`. Its CRoaring dependency was\n`baa32837f9f693aee54aeec97051b54ee522e21a` and hiredis was\n`60e5075d4ac77424809f855ba3e398df7aacefe8`.\n\nThe host reported `Linux-6.18.44-x86_64-with-glibc2.41`, Python 3.12.14, and\n`INTEL(R) XEON(R) PLATINUM 8573C`. All benchmark processes inherited affinity to\nCPUs 0 and 1; the container's CPU quota was four CPUs (`400000 100000`). No\nother builds or tests were running. This remains a virtualized shared host:\nscheduling and CPU-frequency variation affect the samples. Each server used a\nUnix socket, persistence disabled, one client, and pipeline depth one. The run\nstarted at `2026-10-15T18:58:24Z`.\n\nThe native binary was built from the tested source before its commit, so its\nembedded version says `sha=6ee76514:1`. The recorded source revision and binary\nhash below identify what was measured. The baseline embedded version says\n`sha=4e4c65bc:0`.\n\n| Artifact | SHA-256 |\n| --- | --- |\n| Native redis-server | `9de45976ba8cde3efdc021e4ab5486b78c4c60e6f86d29c77ae20c3b774aae9d` |\n| Baseline redis-server | `03e9e9309e76d3cfae162a532e77eb08c87d1d0647f2986f22abdf09d4a20b80` |\n| Shared redis-benchmark client | `0bab90cf0f3fce55c01b7e755cd865ad3ab3601863973fe5784bd6d51d9efac2` |\n| Reference module | `ce9182a912bce173aaa58c6bbe0164f8598ae8e537d78d402e8bf5fa440b1d66` |\n| Raw result JSON | `edc7ea96e7741c59f5105862f61780c7421bf3ff323dac56aeb8690cf98eb857` |\n\nThe exact invocation, from the native checkout using the pre-rename harness,\nwas:\n\n[code example]\n\nThe current harness issues only native `BITRANGEINTARRAY` calls, using\n`BITRANGEINTARRAY key 0 -1` for the retained `get-all` workload label. It does not\nreproduce the historical native `R.*` commands. The raw JSON retains all samples,\nwarmups, request counts, exact reply sizes,\nlatency metrics, build settings, and binary hashes. The JSON and stdout log are\nlocal review artifacts at the paths above, not files in the repository.\n\nThe main observations, using median server execution time, are:\n\n- Sparse 65,536-element `R.RANGEINTARRAY` first-page time is\n  2.30 µs. Before removing the up-front\n  cardinality scan it was 595.18 µs\n  (about 259× higher).\n  The earlier run used 310 requests per trial; this run uses\n  5000, with improved warmup calibration.\n  This diagnostic comparison motivated the change; it is not a controlled\n  cross-version throughput claim. The module's first page is\n  2.87 µs in this run.\n- Sparse 65,536-element middle and last pages take\n  640.80 and\n  900.28 µs natively, versus\n  61,807.50 and\n  3,604.69 µs in the module.\n  Returning the entire sparse array through RANGE takes\n  5.06 ms natively versus\n  6.79 seconds in the module.\n  The module selects each requested rank separately; the native command skips\n  to the first rank and then iterates forward.\n- Native sparse `R.GETINTARRAY` was slower: the 65,536-element case takes\n  3.86 ms versus\n  2.12 ms. The empty page after\n  that bitmap's end takes 641.59 µs natively\n  versus 172.93 µs. Traversing to a\n  distant rank still costs time even when no values are returned.\n- High-offset results use the module's R64 API. They demonstrate the native\n  commands' 64-bit coverage, and should not be labeled a comparison against\n  the module's 32-bit R API. Small-page throughput often reflects scheduling\n  and round-trip overhead more than server execution time. The variance and\n  full matrix below should guide interpretation.\n\nThe very slow sparse RANGE-all case uses one request per trial, so each\nbackend has only three single-command samples there. This bounds runtime but\nmakes its native throughput estimate especially coarse. Other large replies\nare limited by the 32 MiB response budget. Three trials are diagnostic,\nnot a statistical confidence interval; the sample standard deviations below\nexpose variability rather than establish significance. The earlier implementation\nrun is preserved separately as `bitroar-intarray-pre-optimization.json`; the\nintermediate run before improving calibration is\n`bitroar-intarray-cold-calibrated.json`, both in `/workspace/scratch`.\n\nIn the table, `n` is requests per trial for **each** backend, and `ints` is\nreturned integers per request. Server times are microseconds, shown as\n**mean ± sample standard deviation (median)**. Throughput is median complete\nresponses per second. All 50 workloads are included; module times in the\n`high64-4096` rows use R64 commands.\n\n| Dataset / workload | n | ints | Native server µs | Module server µs | Native req/s | Module req/s |\n| --- | ---: | ---: | ---: | ---: | ---: | ---: |\n| empty / get-all | 20,000 | 0 | 0.18 ± 0.12 (0.12) | 0.39 ± 0.08 (0.37) | 67,114.09 | 22,522.52 |\n| empty / range-empty | 7,142 | 0 | 0.16 ± 0.07 (0.16) | 0.54 ± 0.08 (0.51) | 41,766.08 | 12,596.12 |\n| dense-16 / get-all | 12,500 | 16 | 0.93 ± 0.11 (0.92) | 1.62 ± 0.49 (1.37) | 14,654.16 | 18,037.52 |\n| dense-16 / range-first16 | 6,000 | 16 | 1.46 ± 0.10 (1.49) | 1.76 ± 0.27 (1.81) | 11,342.16 | 16,759.78 |\n| dense-16 / range-middle1pct | 4,545 | 1 | 1.00 ± 0.30 (0.85) | 0.98 ± 1.08 (0.39) | 15,000.00 | 126,250.01 |\n| dense-16 / range-last16 | 12,500 | 16 | 1.16 ± 0.16 (1.07) | 1.12 ± 0.23 (1.13) | 18,409.43 | 27,777.78 |\n| dense-16 / range-all | 4,545 | 16 | 1.34 ± 0.29 (1.41) | 1.93 ± 0.54 (1.84) | 11,713.92 | 12,055.70 |\n| dense-16 / range-empty | 4,545 | 0 | 0.59 ± 0.21 (0.47) | 1.08 ± 0.06 (1.07) | 20,659.09 | 22,725.00 |\n| sparse-16 / get-all | 4,166 | 16 | 2.02 ± 0.36 (1.90) | 2.10 ± 0.13 (2.12) | 10,311.88 | 10,467.34 |\n| sparse-16 / range-first16 | 3,333 | 16 | 1.78 ± 0.38 (1.59) | 1.86 ± 0.07 (1.84) | 10,255.38 | 11,000.00 |\n| sparse-16 / range-middle1pct | 10,000 | 1 | 1.00 ± 0.04 (1.00) | 1.06 ± 0.05 (1.09) | 21,505.38 | 19,305.02 |\n| sparse-16 / range-last16 | 6,250 | 16 | 1.93 ± 0.26 (2.03) | 2.13 ± 0.36 (2.08) | 8,445.95 | 11,425.96 |\n| sparse-16 / range-all | 5,555 | 16 | 2.23 ± 0.15 (2.16) | 2.46 ± 0.51 (2.73) | 7,662.07 | 9,694.59 |\n| sparse-16 / range-empty | 10,000 | 0 | 0.93 ± 0.18 (0.91) | 1.20 ± 0.12 (1.23) | 12,738.85 | 15,673.98 |\n| dense-4096 / get-all | 1,217 | 4,096 | 69.58 ± 7.58 (65.74) | 75.41 ± 5.06 (73.03) | 2,212.73 | 2,035.12 |\n| dense-4096 / range-first16 | 3,333 | 16 | 1.26 ± 0.19 (1.17) | 1.65 ± 0.42 (1.48) | 8,771.05 | 20,962.27 |\n| dense-4096 / range-middle1pct | 10,000 | 40 | 1.90 ± 0.04 (1.90) | 2.17 ± 0.04 (2.16) | 14,224.75 | 17,241.38 |\n| dense-4096 / range-last16 | 6,250 | 16 | 1.43 ± 0.16 (1.46) | 1.56 ± 0.55 (1.52) | 16,149.87 | 9,204.71 |\n| dense-4096 / range-all | 980 | 4,096 | 75.89 ± 5.77 (76.18) | 113.44 ± 19.28 (109.67) | 1,519.38 | 1,462.69 |\n| dense-4096 / range-empty | 4,166 | 0 | 0.77 ± 0.21 (0.80) | 0.86 ± 0.77 (0.42) | 8,807.61 | 99,190.48 |\n| sparse-4096 / get-all | 707 | 4,096 | 235.58 ± 29.87 (224.11) | 128.26 ± 1.04 (128.32) | 1,370.16 | 1,716.02 |\n| sparse-4096 / range-first16 | 5,555 | 16 | 3.09 ± 0.82 (3.55) | 2.78 ± 0.06 (2.78) | 13,226.19 | 10,268.02 |\n| sparse-4096 / range-middle1pct | 2,000 | 40 | 30.53 ± 5.64 (28.01) | 246.84 ± 39.70 (225.79) | 7,604.56 | 1,964.64 |\n| sparse-4096 / range-last16 | 1,282 | 16 | 42.41 ± 1.12 (42.32) | 211.27 ± 12.30 (214.55) | 19,134.33 | 2,143.81 |\n| sparse-4096 / range-all | 25 | 4,096 | 254.59 ± 72.52 (269.76) | 23,600.52 ± 1,959.07 (24,525.28) | 1,562.50 | 40.06 |\n| sparse-4096 / range-empty | 2,941 | 0 | 50.57 ± 5.96 (49.44) | 14.45 ± 3.02 (13.07) | 9,306.96 | 8,939.21 |\n| dense-65536 / get-all | 58 | 65,536 | 1,414.02 ± 88.74 (1,431.50) | 1,443.66 ± 146.34 (1,398.02) | 133.03 | 176.83 |\n| dense-65536 / range-first16 | 5,000 | 16 | 1.78 ± 0.47 (1.66) | 1.54 ± 0.63 (1.47) | 8,726.00 | 18,315.02 |\n| dense-65536 / range-middle1pct | 1,923 | 655 | 25.37 ± 10.59 (25.68) | 18.12 ± 0.35 (18.13) | 6,771.13 | 15,892.56 |\n| dense-65536 / range-last16 | 12,500 | 16 | 2.08 ± 0.36 (2.16) | 1.03 ± 0.27 (0.90) | 11,415.52 | 99,206.34 |\n| dense-65536 / range-all | 55 | 65,536 | 1,429.19 ± 212.79 (1,405.24) | 1,913.15 ± 295.61 (1,769.47) | 125.00 | 157.59 |\n| dense-65536 / range-empty | 7,142 | 0 | 0.91 ± 0.17 (0.94) | 1.97 ± 1.75 (1.78) | 10,144.89 | 13,349.53 |\n| sparse-65536 / get-all | 40 | 65,536 | 3,944.09 ± 440.02 (3,857.20) | 2,585.43 ± 817.58 (2,117.68) | 101.78 | 116.96 |\n| sparse-65536 / range-first16 | 5,000 | 16 | 2.28 ± 0.27 (2.30) | 2.66 ± 0.41 (2.87) | 13,927.58 | 10,869.57 |\n| sparse-65536 / range-middle1pct | 10 | 655 | 671.73 ± 357.60 (640.80) | 70,637.87 ± 16,415.90 (61,807.50) | 1,428.57 | 16.05 |\n| sparse-65536 / range-last16 | 169 | 16 | 900.62 ± 205.02 (900.28) | 3,641.74 ± 576.90 (3,604.69) | 1,076.43 | 208.13 |\n| sparse-65536 / range-all | 1 | 65,536 | 4,690.33 ± 725.29 (5,056.00) | 6,450,050.00 ± 860,410.60 (6,790,363.00) | 90.91 | 0.15 |\n| sparse-65536 / range-empty | 641 | 0 | 643.46 ± 3.74 (641.59) | 173.07 ± 1.85 (172.93) | 959.58 | 5,297.52 |\n| bitset-65536 / get-all | 38 | 65,536 | 1,390.46 ± 121.46 (1,396.53) | 1,391.28 ± 126.03 (1,380.71) | 156.38 | 143.94 |\n| bitset-65536 / range-first16 | 7,142 | 16 | 1.64 ± 0.08 (1.65) | 1.27 ± 0.56 (1.05) | 15,766.00 | 66,129.62 |\n| bitset-65536 / range-middle1pct | 3,550 | 655 | 17.25 ± 2.60 (18.03) | 47.56 ± 1.96 (48.27) | 7,717.39 | 3,629.86 |\n| bitset-65536 / range-last16 | 2,272 | 16 | 5.45 ± 1.90 (5.15) | 32.03 ± 0.48 (32.02) | 7,624.16 | 24,170.21 |\n| bitset-65536 / range-all | 6 | 65,536 | 2,177.61 ± 206.35 (2,236.67) | 103,734.72 ± 13,099.46 (102,373.83) | 88.24 | 9.06 |\n| bitset-65536 / range-empty | 20,000 | 0 | 0.38 ± 0.10 (0.37) | 1.54 ± 0.82 (1.88) | 43,196.54 | 13,577.73 |\n| high64-4096 / get-all | 511 | 4,096 | 301.96 ± 80.29 (286.76) | 325.60 ± 23.66 (330.44) | 1,296.95 | 1,327.27 |\n| high64-4096 / range-first16 | 12,500 | 16 | 1.64 ± 0.40 (1.70) | 3.90 ± 0.30 (4.04) | 37,313.43 | 25,987.53 |\n| high64-4096 / range-middle1pct | 588 | 40 | 26.44 ± 3.07 (26.62) | 868.15 ± 46.39 (847.25) | 14,000.00 | 1,157.48 |\n| high64-4096 / range-last16 | 724 | 16 | 53.14 ± 11.44 (52.10) | 738.26 ± 67.57 (708.62) | 13,660.38 | 1,304.50 |\n| high64-4096 / range-all | 5 | 4,096 | 260.27 ± 79.58 (256.20) | 99,447.67 ± 24,630.55 (87,323.20) | 714.29 | 11.21 |\n| high64-4096 / range-empty | 7,142 | 0 | 56.26 ± 5.75 (56.05) | 43.60 ± 1.57 (43.22) | 9,251.29 | 19,302.70 |"
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "sh",
      "code": "make -j4\npython3 tools/bitroar-intarray-bench.py --json-out /tmp/intarray-native.json",
      "section_id": "overview"
    },
    {
      "id": "overview-ex1",
      "language": "sh",
      "code": "git clone https://github.com/aviggiano/redis-roaring.git /tmp/redis-roaring\ngit -C /tmp/redis-roaring checkout e7382b7cea1ec495304e8aa60916c49673e74c1d\ngit -C /tmp/redis-roaring submodule update --init deps/CRoaring deps/hiredis\n(cd /tmp/redis-roaring/src && ../deps/CRoaring/amalgamation.sh)\ncmake -S /tmp/redis-roaring -B /tmp/redis-roaring-build -DCMAKE_BUILD_TYPE=Release\ncmake --build /tmp/redis-roaring-build --target redis-roaring -j4\npython3 tools/bitroar-intarray-bench.py \\\n  --module /tmp/redis-roaring-build/libredis-roaring.so \\\n  --module-src-dir /path/to/unmodified-base/src \\\n  --module-revision e7382b7cea1ec495304e8aa60916c49673e74c1d \\\n  --json-out /tmp/intarray-comparison.json",
      "section_id": "overview"
    },
    {
      "id": "historical-measured-comparison-before-the-command-rename-and-consolidation-2026-10-15-ex0",
      "language": "sh",
      "code": "taskset -c 0,1 python3 tools/bitroar-intarray-bench.py \\\n  --module /workspace/scratch/intarray-module-build/libredis-roaring.so \\\n  --module-src-dir /workspace/redis-intarray-baseline/src \\\n  --module-revision e7382b7cea1ec495304e8aa60916c49673e74c1d \\\n  --requests 20000 --trials 3 \\\n  --json-out /workspace/scratch/bitroar-intarray-comparison.json \\\n  > /workspace/scratch/bitroar-intarray-comparison.log 2>&1",
      "section_id": "historical-measured-comparison-before-the-command-rename-and-consolidation-2026-10-15"
    }
  ]
}
