mbutrovich opened a new pull request, #12470:
URL: https://github.com/apache/arrow-rs/pull/12470

   # Which issue does this PR close?
   
   - Part of #12467.
   
   # Rationale for this change
   
   This is the proof of concept @alamb suggested in 
https://github.com/apache/arrow-rs/issues/12467#issuecomment-7167463717: a new 
crate, patterns duplicated between arrow and parquet moved into it, and the 
call sites refactored to use it. It is a draft to show what the move touches 
and costs, not a PR to merge as is.
   
   # What changes are included in this PR?
   
   A new crate, `arrow-bitutils`, with no dependencies. It is registered in the 
workspace, CI, Miri, the labeler, and the release instructions the same way as 
`arrow-cmp`.
   
   - `byte_util` adds `cmp_bytes`, `common_prefix_len`, and `prefix_key_u128`. 
`cmp_bytes` compares the first 8 bytes of each value as big-endian integers and 
scans the rest only on a tie. It is `#[inline(always)]` because LLVM kept a 
`#[inline]` version out of line in `ByteArrayEncoder::write_gather`. 
`common_prefix_len` stays out of line and is a leaf.
   - `bit_chunk_iterator` (`UnalignedBitChunk`, `BitChunks`) moves from 
`arrow-buffer`. `arrow-buffer` re-exports the module, so 
`arrow_buffer::bit_chunk_iterator` paths are unchanged.
   
   Call sites:
   
   - parquet depends on `arrow-bitutils` without the `arrow` feature. Both 
`DELTA_BYTE_ARRAY` encoders use `common_prefix_len` in place of 
`parquet/src/util/prefix.rs`. The arrow writer's `is_greater` and the column 
writer's `compare_greater` use `cmp_bytes` for `BYTE_ARRAY` and 
`FIXED_LEN_BYTE_ARRAY`, which is the comparison from #12460 in shared form. 
parquet keeps one `count_set_bits`, on `UnalignedBitChunk::count_ones`.
   - arrow-ord `rank` uses `prefix_key_u128` in place of its own 
`byte_view_key`.
   - CONTRIBUTING.md asks contributors to check `arrow-bitutils` before adding 
a word-at-a-time loop at a call site.
   
   What the move costs:
   
   - `BitChunks::new` has no `#[inline]`, so the calls inside `arrow-buffer` to 
it (the `buffer_bin_*` functions, the `BooleanBuffer` bitwise-assign impls, 
`NullBuffer::contains`, and others) now cross a crate boundary and stay out of 
line without LTO. Each runs once per operation. Downstream crates already 
called it across a crate boundary.
   - Code below `arrow-buffer` can't use `Buffer` or `BooleanBuffer`. The 
`bit_chunk_iterator` tests stay in `arrow-buffer` because they build their 
inputs with `Buffer`, and moving `bit_util` or `bit_iterator` would cost more 
of the same.
   - Sharing a helper that is `pub(crate)` today, such as `read_u64`, needs a 
new public function in `arrow-bitutils`.
   
   # Are these changes tested?
   
   Yes. `arrow-bitutils/src/byte_util.rs` tests each function against a naive 
reference, at every word and block boundary, at unaligned offsets, and on 
random input. The `bit_chunk_iterator` tests moved to 
`arrow-buffer/src/util/bit_chunk_iterator_tests.rs` unchanged. The existing 
parquet statistics and `DELTA_BYTE_ARRAY` tests cover the call sites.
   
   These benchmarks cover the changed paths: `arrow_writer` (string, binary, 
and `DELTA_BYTE_ARRAY` cases), `boolean_append_packed`, `buffer_bit_ops`, 
`boolean_kernels`, `arrow_reader` (skip cases), `sort_kernel` (`rank 
string_view`), and `set_bit_counter`. The new `byte_util` bench compares each 
primitive with the code it replaces.
   
   # Are there any significant user-facing changes?
   
   A new crate, `arrow-bitutils`, with public items `byte_util::{cmp_bytes, 
common_prefix_len, prefix_key_u128}` and the moved `bit_chunk_iterator` types. 
parquet gains a required dependency on it, which adds no third-party crates. No 
breaking changes.
   
   # AI usage disclosure
   
   I wrote this PR with help from Claude but understand and support the core 
approach, implementation, and test coverage.
   


-- 
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