Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[common] Using a faster deserialization method in RoaringBitmap32 #4765

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

Tan-JiaLiang
Copy link
Contributor

Purpose

In RoaringBitmap, the deserialize(java.io.DataInput, byte[]) function has a better performance to deserialize the BitmapContainer.

Tests

No.

API and Format

No.

Documentation

No.

@JingsongLi
Copy link
Contributor

Can you provide the benchmark result?

@Tan-JiaLiang
Copy link
Contributor Author

I'm trying to understand how to use the benchmark in paimon, and I hope my benchmark using in correct.

bitmap32-deserialize-benchmark Best/Avg Time(ms) Row Rate(K/s) Per Row(ns) Relative
bitmap32-deserialize-benchmark_without-buffer 239 / 259 0.4 2385027.0 1.0X
bitmap32-deserialize-benchmark_with-buffer 2 / 2 54.1 18500.0 128.9X

@JingsongLi
Copy link
Contributor

Thanks for your information.

@@ -89,6 +91,10 @@ public void deserialize(DataInput in) throws IOException {
roaringBitmap.deserialize(in);
}

public void deserialize(DataInput in, @Nullable byte[] buffer) throws IOException {
roaringBitmap.deserialize(in, buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

if deserialize(in, null) is better, can you just modify RoaringBitmap32.deserialize(DataInput)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree with this, but be aware that it may take up 8KB of memory during deserialization, although I think it's reasonable.

@@ -86,7 +86,7 @@ public void serialize(DataOutput out) throws IOException {
}

public void deserialize(DataInput in) throws IOException {
roaringBitmap.deserialize(in);
roaringBitmap.deserialize(in, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can tested roaringBitmap.deserialize(ByteBuffer bbf) directly? We actually know the exact byte count of the bitmap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean adding a benchmark?

Copy link
Contributor

Choose a reason for hiding this comment

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

From the test results, it is more optimal, and I have checked other formats, which also use it. we can just use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The premise of ByteBuffer is that we need to know the actual size of the Bitmap. This seems to require recording the actual size at serialisation time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can using it in delection vector bitmap and rbm aggregate function, but the bitmap and bsi index can not for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

roaringBitmap.deserialize(ByteBuffer bbf)

Does the bitmap index not record the byte size? Would you be willing to integrate roaringBitmap.deserialize(ByteBuffer bbf) into a usable place such as dv?

@Tan-JiaLiang
Copy link
Contributor Author

Add the deserialize(ByteBuffer) benchmark

bitmap32-deserialize-benchmark Best/Avg Time(ms) Row Rate(K/s) Per Row(ns) Relative
benchmark_deserialize(DataInput) 242 / 254 0.4 2417750.0 1.0X
benchmark_deserialize(DataInput, byte[]) 2 / 3 49.8 20087.0 120.4X
benchmark_deserialize(ByteBuffer) 1 / 2 75.3 13287.0 182.0X

Copy link
Contributor

@JingsongLi JingsongLi left a comment

Choose a reason for hiding this comment

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

Hi @Tan-JiaLiang , can you use null for bitmap index, and use ByteBuffer for deletion vectors?

@Tan-JiaLiang Tan-JiaLiang force-pushed the faster_bitmap_deserialize branch from 1b0cecd to f5272c2 Compare December 27, 2024 09:22
@Tan-JiaLiang Tan-JiaLiang changed the title [common] Add a faster deserialize function to RoaringBitmap32 [common] Using a faster deserialization method in RoaringBitmap32 Dec 27, 2024
@Tan-JiaLiang
Copy link
Contributor Author

@JingsongLi @Zouxxyy Can you help to review again?

if (magicNum == BitmapDeletionVector.MAGIC_NUMBER) {
return BitmapDeletionVector.deserializeFromDataInput(dis);
return BitmapDeletionVector.deserializeFromByteBuffer(buffer.slice());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is slice needed here

Copy link
Contributor Author

@Tan-JiaLiang Tan-JiaLiang Dec 27, 2024

Choose a reason for hiding this comment

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

This is really just a programming convention to ensure that the ByteBuffer passed in are bitmaps only. I take a look that it is already using in RoaringArray#deserialize, so it's redundant here.

https://github.com/RoaringBitmap/RoaringBitmap/blob/60dcdb58846037ea8ea712317a0ac887e00fe25b/roaringbitmap/src/main/java/org/roaringbitmap/RoaringArray.java#L544-L550

@Tan-JiaLiang
Copy link
Contributor Author

Tan-JiaLiang commented Dec 27, 2024

Seems the CDC test case is still having some thread safe problem, I will take a look in next week. Can someone help to trigger the build one more time?

Copy link
Contributor

@Zouxxyy Zouxxyy left a comment

Choose a reason for hiding this comment

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

+1

@JingsongLi JingsongLi merged commit 8157be9 into apache:master Dec 28, 2024
12 checks passed
Zouxxyy pushed a commit to Zouxxyy/incubator-paimon that referenced this pull request Jan 3, 2025
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