Improve comparison kernels for register-aligned `FixedSizeBinary`sizes
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 167
Description
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
This is based on: https://discord.com/channels/885562378132000778/1450910501369286746
Currently, the comparison kernels for `FixedSizeBinary`, `Eq` and `Lt` (and thus also the other basic comparison operators) rely on the `ArrayOrd` impl for `FixedSizeBinary`.
This is currently implemented as a `&[u8] == &[u8]` (`T::Item` is `&[u8]`) comparison, which will result in a libc `bcmp@GOTPCREL` call.
Furthermore, canonical extensions like UUID are built upon `FixedSizeBinary`. UUIDs are 128-bit and thus are a perfect fit for AVX 128-bit registers.
**Describe the solution you'd like**
I would like arrow-rs to use better cmp instructions in these cases. For this, we need to forward the fixed size of our binary elements to the comparison function.
This will lead to more code, but we can limit this to sizes where we actually see a difference.
I have one example implementation [here](https://github.com/apache/arrow-rs/compare/main...valkum:arrow-rs:improved-bin) that allowed me to collect some benchmarks (run on a noisy macbook pro m1 max). See the first commit in my branch for the benchmark code.
```
FixedSizeBinary: comparison benchmarks/eq FixedSizeBinary<16>
time: [79.100 µs 79.590 µs 80.465 µs]
change: [-39.566% -38.918% -38.196%] (p = 0.00 < 0.05)
Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severe
FixedSizeBinary: comparison benchmarks/eq scalar FixedSizeBinary
time: [74.613 µs 75.119 µs 76.120 µs]
change: [-42.516% -42.100% -41.551%] (p = 0.00 < 0.05)
Performance has improved.
Found 17 outliers among 100 measurements (17.00%)
4 (4.00%) high mild
13 (13.00%) high severe
```
My impl (second commit) was just quick and dirty to prove a point. There might be different ways to solve this issue.
**Describe alternatives you've considered**
Other options include the ability to provide specialized kernels you can opt in to (for example in datafusion) to avoid bloating the size of arrow-rs. In this case, I think there should be a collection of said specialized kernels, at least for canonical extensions.
I haven't done any comparison on emitted code size. So I guess it comes down to the fixed sizes we pick and how much size this adds to arrow-rs.
**Additional context**
This was inspired by looking into the call stack for operations on UUIDs. So I would like to at least include 128 as a size.
Contributor guide
Research direction
Start with the FixedSizeBinary comparison kernels and its ArrayOrd implementation, focusing on Eq, Lt, and the other basic comparison operators. Review the linked improved-bin example and its first-commit benchmark code, then evaluate selected fixed sizes including 128; done means optimized comparisons with benchmark evidence and an understood code-size tradeoff.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100