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

   # Which issue does this PR close?
   
   - Relates to https://github.com/apache/arrow-rs/pull/11771
   
   # Rationale for this change
   
   While investigating the `Utf8View` `convert_rows` benchmark variance 
observed on #11771, inspecting `arrow-row/src/variable.rs` showed several 
avoidable overheads in `decoded_len` and `decode_binary_view_inner`:
   
   1. `decoded_len` delegates to `decode_blocks` with a closure and was not 
inlined, causing a per-row call, unnecessary slice bounds checks on unread 
bytes, and extra block-length arithmetic on ARM64.
   2. In `decode_binary_view_inner`, null and empty rows still ran 
`decode_blocks` and a redundant `null_sentinel` check even though `views` is 
zero-initialized and `0_u128` is already valid for both null and empty views.
   3. Non-inlined strings (`> 12` bytes) still went through `#[inline(never)] 
make_view` (and its 13-way inline length dispatch) before branching again on 
`decoded_len <= MAX_INLINE_VIEW_LEN`.
   4. `options.descending` was checked inside the per-row loop, keeping the 
bit-inversion loop inside the ascending hot path.
   
   # What changes are included in this PR?
   
   Minimal changes confined to `arrow-row/src/variable.rs` (no public API 
changes; removes an existing `unsafe` block):
   
   - Inline `decoded_len` and scan block sentinels directly without 
constructing unread slices (benefits both `decode_binary` and 
`decode_binary_view`).
   - Skip `decode_blocks` early in `decode_binary_view_inner` when `row[0] != 
non_empty_sentinel`.
   - Construct `> 12`-byte views inline via 
`ByteView::new(...).with_offset(...).as_u128()` and keep `make_view` only for 
`<= 12`-byte inline values.
   - Specialize `decode_binary_view_inner<VALIDATE_UTF8, DESCENDING>` (kept 
`#[inline(never)]` so ascending and descending frames stay separate) and zip 
`views.iter_mut()` with `rows.iter_mut()` to avoid per-row bounds checks.
   
   # Benchmarks
   
   Targets `arrow/benches/row_format.rs` (`convert_rows` and 
`convert_rows_parsed` for `string view(...)` and `string(...)`).
   
   Local `perf stat` user-space counters (`5,000 × 4,096` rows, `x86_64`, 
`CARGO_PROFILE_RELEASE_LTO=thin`):
   
   | Workload | Instructions | Branches | Branch Misses |
   |---|---:|---:|---:|
   | `string view(1..100, 0.5)` raw (random, nullable) | -15.9% | -16.3% | 
-31.0% |
   | `string view(1..100, 0.5)` parsed | -12.6% | -17.1% | -15.4% |
   | `string view(1..100, 0)` raw (random, all valid) | -13.0% | -10.6% | -7.8% 
|
   | `string view(100, 0.5)` raw (constant, nullable) | -13.8% | -13.4% | -4.9% 
|
   | `string view(100, 0)` raw (constant, all valid) | -11.2% | -8.3% | -11.9% |
   | `string view(30, 0)` raw (constant, all valid) | -14.6% | -13.0% | +20.7% 
(tiny baseline: 179K -> 216K) |
   | `string view(10, 0)` raw (all inline, all valid) | -12.4% | -8.7% | +1.9% 
(tiny baseline: 194K -> 197K) |
   | `string view(1..100, 0.5)` descending | -12.9% | -14.2% | -13.3% |
   | `string view(100, 0)` descending | -8.8% | -7.3% | -0.1% |
   | `string(100, 0)` / `string(100, 0.5)` | -3.4% / -4.5% | -3.0% / -4.7% | 
-19.4% / -26.7% |
   
   Ablation on `string view(1..100, 0.5)` instructions:
   - Inlined direct `decoded_len` alone: `-7.7%`
   - + Null/empty early skip and inline `ByteView::new` for `> 12`B: `-14.4%`
   - + `const DESCENDING` specialization and `zip`: `-15.9%`
   
   No tested inputs (constant or random lengths, inline or non-inline, 
all-valid or nullable, ascending or descending, raw or UTF-8 validated) 
regressed.
   
   # Are these changes tested?
   
   Covered by the existing `arrow-row` test suite (110 unit tests including 
`fuzz_test` across all `SortOptions`, `Utf8View`/`BinaryView`, and `RowParser`, 
plus 8 doctests), verified in both debug and release modes.
   
   # Are there any user-facing changes?
   
   No.
   
   # AI usage
   
   This investigation and patch were developed with assistance from Gemini 4 
Neon (including disassembly/perf analysis, ablation testing, and 
implementation); all code and benchmarks were reviewed and verified.
   


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