-
Notifications
You must be signed in to change notification settings - Fork 860
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
Minor: Clarify documentaiton on NullBufferBuilder::allocated_size
#7089
base: main
Are you sure you want to change the base?
Conversation
@@ -83,7 +83,23 @@ impl BooleanBufferBuilder { | |||
self.len == 0 | |||
} | |||
|
|||
/// Returns the capacity of the buffer | |||
/// Returns the capacity of the buffer, in bits (not bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key detail is that this function returns the value in bits
(not bytes)
@@ -217,7 +217,7 @@ impl NullBufferBuilder { | |||
self.bitmap_builder.as_mut().map(|b| b.as_slice_mut()) | |||
} | |||
|
|||
/// Return the allocated size of this builder, in bytes, useful for memory accounting. | |||
/// Return the allocated size of this builder, in bits, useful for memory accounting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This documentation is wrong -- as it uses capacity()
directly which returns a size in bits
I actually think it would be better if we had a function that returned allocated size in bytes (maybe we can deprecate this one and make a new one like allocated_bytes()
or something for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I also noticed in #7082
One thing to note is that NullBufferBuilder::allocated_size()
is used here:
arrow-rs/arrow-array/src/builder/generic_bytes_view_builder.rs
Lines 397 to 408 in 92cfd99
/// Return the allocated size of this builder in bytes, useful for memory accounting. | |
pub fn allocated_size(&self) -> usize { | |
let views = self.views_builder.capacity() * std::mem::size_of::<u128>(); | |
let null = self.null_buffer_builder.allocated_size(); | |
let buffer_size = self.completed.iter().map(|b| b.capacity()).sum::<usize>(); | |
let in_progress = self.in_progress.capacity(); | |
let tracker = match &self.string_tracker { | |
Some((ht, _)) => ht.capacity() * std::mem::size_of::<usize>(), | |
None => 0, | |
}; | |
buffer_size + in_progress + tracker + views + null | |
} |
And I think it's used with assumption it provides bytes not bits, so may need adjustment.
/// // empty requires 0 bytes | ||
/// let b = BooleanBufferBuilder::new(0); | ||
/// assert_eq!(0, b.capacity()); | ||
/// // Creating space for 1 bit results in 64 bytes (space for 512 bits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a small note here explaining why it over allocates?
Which issue does this PR close?
Related to
Rationale for this change
@Chen-Yuan-Lai found in apache/datafusion#14504 that
NullBufferBuilder::allocated_size
actually reports the size in bits, not bytes -- nice eyes!What changes are included in this PR?
Update the documentation to reflect what the code does
BooleanBufferBuilder::capacity
to verify it is in terms of bitsAre there any user-facing changes?
Better docs