Skip to content

perf(rowids): count bitmap bits a word at a time - #8642

Merged
Xuanwo merged 1 commit into
lance-format:mainfrom
pengw0048:peng/rowid-bitmap-popcount
Aug 28, 2026
Merged

Xuanwo merged 1 commit into
lance-format:mainfrom
pengw0048:peng/rowid-bitmap-popcount

Conversation

@pengw0048

Copy link
Copy Markdown
Contributor

Problem

Bitmap::count_ones walks the bitmap one byte at a time. A row id sequence
asks for that count on the hot paths:

  • U64Segment::len counts the whole bitmap of a RangeWithBitmap segment, and
    RowIdIndex::new calls len on every segment of every fragment.
  • U64Segment::position counts the bits up to the wanted offset, once per
    lookup.

On a 15.43B row / 17,601 fragment dataset whose sequences hold 3.36 GB of
bitmaps, that byte-at-a-time count is the whole cost of opening the index.

Change

Count a u64 at a time, and keep the byte loop for the trailing bytes and for
the two partial bytes at the ends of a slice.

Measurement

Taking one row id from that dataset, release build, 96-core Linux x86-64. The
index here is the per-fragment index from #8624, which calls len per segment:

before after
first _take_rows, 1 row id 1.92 s 1.41 s
second call, same dataset object 1.10 s 0.61 s

cargo test -p lance-table --lib rowids: 98 passed.

`Bitmap::count_ones` walked one byte at a time. A row id sequence asks
for it twice on every lookup path: `U64Segment::len` counts the whole
bitmap of a `RangeWithBitmap` segment, and `position` counts the bits up
to the offset.

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The word-at-a-time popcount preserves whole-bitmap and slice semantics while directly reducing CPU work on the row-id hot paths.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 21, 2026
@Xuanwo
Xuanwo merged commit 0a4e20e into lance-format:main Aug 28, 2026
35 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants