sunchao commented on code in PR #12024:
URL: https://github.com/apache/arrow-rs/pull/12024#discussion_r4444300490


##########
arrow-buffer/src/builder/boolean.rs:
##########
@@ -276,9 +276,31 @@ impl BooleanBufferBuilder {
         self.advance(additional);
 
         let offset = self.len() - additional;
-        for (i, v) in slice.iter().enumerate() {
+        let buffer = self.buffer.as_slice_mut();
+
+        // Set bits individually until the write position is byte aligned
+        let head = ((8 - offset % 8) % 8).min(additional);

Review Comment:
   For slices shorter than eight booleans, no packed byte can be written, but 
each call still goes through the head and tail setup. I measured consecutive 
appends into a preallocated builder starting at bit offset 3, cycling the slice 
length from 1 through 7. On AMD EPYC Milan with rustc 1.97.1 in release mode, 
random input went from 23.2 to 25.8 ns/call and all-false input from 4.75 to 
6.76 ns/call. A local control that used one scalar loop for `len < 8` brought 
those down to about 23 and 5.3 ns/call, respectively. Could we keep a single 
scalar path for these short slices and add a repeated-short-append case 
alongside the 64Ki benchmark?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to