Skip to content

Conversation

@anandheritage
Copy link
Contributor

@anandheritage anandheritage commented Jul 29, 2025

Copy-on-Write Implementation for Roaring Bitmap

Overview

This document provides a comprehensive explanation of the copy-on-write (CoW) implementation for Roaring Bitmap, specifically addressing GitHub issue #193. The implementation enables efficient conversion of memory-mapped Roaring Bitmaps to mutable bitmaps by sharing containers until modification is required.

What is Copy-on-Write?
Copy-on-Write is a resource management technique where multiple copies of data can share the same underlying storage until one of them needs to modify the data. At that point, a private copy is created for the modifier, while other references continue to share the original data.

Benefits

Memory Efficiency: Shared containers reduce memory usage
Lazy Evaluation: Containers are only copied when modified.

**High-Level Design

ImmutableRoaringBitmap

toMutableRoaringBitmapCopyOnWrite()

CopyOnWriteRoaringBitmap

[Shared Containers] → [Private Copy on Modify]**

Key Components
CopyOnWriteRoaringBitmap: Main class extending MutableRoaringBitmap
needsCopy Array: Tracks which containers require copying
appendCopyOnWrite Methods: Enable container sharing in MutableRoaringArray
Lazy Copying Logic: Defers container duplication until modification

@anandheritage anandheritage changed the title Anandsh/cow Implement copy on write roaring bitmaps Jul 29, 2025

// Test iteration
int count = 0;
for (int value : cow) {

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'int value' is never read.

// Original should still have 100 elements
int originalCount = 0;
for (int value : immutable) {

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'int value' is never read.
@anandheritage
Copy link
Contributor Author

@lemire Can you help me review this ?

@lemire
Copy link
Member

lemire commented Jul 30, 2025

This looks very reasonable. Would you add a short section to the README file?

@anandheritage
Copy link
Contributor Author

This looks very reasonable. Would you add a short section to the README file?

Done. Thanks ! Let me know if anything else required.

@lemire lemire merged commit 18154f1 into RoaringBitmap:master Jul 30, 2025
7 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.

3 participants