Live data from Hacker News

Roaring bitmaps: what they are and how they work

vikramoberoi.com

31–40 of 61 posts

Re: Roaring bitmaps: what they are and how they work

#31

> When a set is sparse, traditional bitmaps compress poorly. They waste space. But if you were to compress them, they'd compress very well. As in, for example, if you were to compress them using roaring bitmaps.

Maybe the author means they compress poorly under generic, common compression algorithms. This is an exotic compression.

Re: Roaring bitmaps: what they are and how they work

#32

I thought the trick was going to be indirection. sorted-list/bitmap/runs, in a two level tree. cool. it's technically missing sorted compliment-list, i.e. only the items that are missing, although worst case runs only use twice as much space, so more complexity without much savings, esp. considering real workloads performs better with sequential ids than random uuids because you use fewer pages further research inves…

Lucene's adaptation of Roaring uses the complement idea on a block-wise basis:

https://github.com/apache/lucene/blob/84cae4f27cfd3feb3bb42d...

Re: Roaring bitmaps: what they are and how they work

#33
This is an excellent write up on Roaring Bitmap. The concrete examples really help to illustrate the algorithm well.

While Roaring Bitmap performs well on space saving with good performance, my gut feeling is there're better ways to achieve the same goals, especially it involving sorting on insertion and binary search on lookup, both on the sorted top level list and the sorted lower-bit integers.

Also it works well on 32-bit integers and probably 64-bit integers but it's not clear it can scale well beyond to bigger integers.

Nevertheless it's an excellent algorithm that works well in practice.

Re: Roaring bitmaps: what they are and how they work

#34
post #26

Earlier quoted context omitted.

This article has a section titled "how Roaring bitmaps are represented in memory". I suggest you actually read the article, it will likely answer all your questions.

I was actually asking how they were serialized and stored on disk.

[deleted]

Re: Roaring bitmaps: what they are and how they work

#35

Can someone explain how this is laid out in memory and what it would look like serialized? It's easy to have an array of N size that fits all bits and just write to disk. You can also mmap a file as a large array of bytes and just mutate it and let the OS handle the disk syncs if you're okay with some data loss of recent state changes if the machine crashes. What would an array of pointers to X containers which are N…

The containers are not in a contiguous memory block. To serialize it, you could write out each container as a length prefixed block with the container id, which is the 16-bit MSB of the container. The top level sorted list can be ignored, as it can be reconstructed.

To de-serialize, read each container by reading its prefix length and its container id, and then read the rest of the container by the length. The top level list is sorted by the container id. It can be reconstructed by inserting the container id with the container memory pointer into the sorted list.

Re: Roaring bitmaps: what they are and how they work

#36

I see this common theme among very fast practical algorithms (like timsort or pdqsort) where there is not some secret math or algorithm, rather they are just a bunch of special cases based on heuristics. Often they involve specific knowledge of the hardware instead of treating software as abstract. To me this is the big difference between “computer science” and “computer engineering”.

Much of this is just threshold effects for algorithm performance, not special cases per se. You don't even need to have specific knowledge of the hardware as long as you can identify cross-over points where one algorithm starts significantly outperforming others. An old HPC trick is to write software that thoroughly measures several algorithm strategies on your specific hardware environment and then code-gens an algo…

In 2000 came across a binary space partition algo that did this, but used a small scheme interpreter to codegen the c++ BSP code. Would love to find out the library name... have now forgotten it.

Re: Roaring bitmaps: what they are and how they work

#37

It looks a bit too simplistic: Blocks with up to 4k items are stored as sorted lists. Having to insert in a sorted list up to 4k items seems very expensive to me.

The full arrays do get expensive, although not too bad. I work at FeatureBase and we have a whole analytics DB built on a roaring variant... for perf reasons it's usually worth it to bias toward the bitmap representation when you get past about 2k set bits, though it does take a bit more space.

Re: Roaring bitmaps: what they are and how they work

#38

> When a set is sparse, traditional bitmaps compress poorly. They waste space. But if you were to compress them, they'd compress very well. As in, for example, if you were to compress them using roaring bitmaps.

Maybe the author means they compress poorly under generic, common compression algorithms. This is an exotic compression.

Yeah pretty much. General purpose compression algorithms do a good job but pale in comparison to what Roaring achieves.

I wouldn't use the word exotic but rather specialized and/or optimized.

Infact later versions of Roaring use run-length-encoding (RLE) containers in addition to array and bitmap containers which is a technique shared with more traditional/general compression algorithms.

In effect rather than achieving "very good" compression, Roaring is very close to "optimal" compression for sparse bitmaps.

Re: Roaring bitmaps: what they are and how they work

#39

Not .bmp bitmaps used to store photographic images as I would have guessed: > Bitmaps are arrays of bits used to store sets of integers. They work by setting the Nth bit when an integer N is in the set

I was confused until I clicked on the provided link in the article to see they’re talking about bit maps. For me that space has always been critical.

Re: Roaring bitmaps: what they are and how they work

#40
post #26

Earlier quoted context omitted.

This article has a section titled "how Roaring bitmaps are represented in memory". I suggest you actually read the article, it will likely answer all your questions.

I was actually asking how they were serialized and stored on disk.

The on-disk format is documented in the spec: https://github.com/RoaringBitmap/RoaringFormatSpec

It's very simple actually. I worked on adding run container support which involved adding support for the newer serialization format in roaring-rs and it proved quite elegant.

Post reply on HN