Repository navigation
Conversation
|
|
|
|
|
@dmitry-chirkov-dremio Based on our prior conversation, here are the benchmark measurements evaluating the direct prefix path versus the adaptive sampling heuristic on GH-55254. Benchmark Notes: Direct Prefix (Option A) vs. Adaptive Sampling (Option B)We evaluated the adaptive heuristic prototyping 32 evenly spaced sampled pairs per batch (triggering the prefix path on >= 4 sample rejections for mixed types, >= 8 for view/view, and falling back to the baseline executor below 4,096 rows): Comparative Benchmark Results:
Takeaways:
|
|
|
…gView equality kernels ### Rationale for this change In apache#55171, direct comparison kernels were added between StringView/BinaryView and offset-based string types. Those kernels relied on `applicator::ScalarBinary` with `ArrayIterator<BinaryViewType>`, which eagerly calls `util::FromBinaryView` and resolves variadic payload pointers for every element regardless of match outcome. As discussed in apache#55254, equality comparisons (`equal`, `not_equal`) can check the view's 4-byte inline prefix and string length before accessing payload buffers, rejecting mismatches early. ### What changes are included in this PR? 1. `util::EqualBinaryViewString`: Added in `arrow/util/binary_view_util.h` to compare a `BinaryViewType::c_type` with contiguous string data. It checks length and 4-byte prefix before dereferencing view variadic buffers. 2. Dedicated equality kernels: Implemented `ViewCompareViewEqual` and `ViewCompareStringEqual` in `scalar_compare.cc`, replacing eager iterator resolution for `equal` and `not_equal`. 3. Register-pinned scalar comparisons: For array-scalar operations, unpacked scalar length and prefix are pinned in registers outside the loop, avoiding repeated scalar lookups. 4. Tests: Extended `TestBinaryViewCompareKernel.ArrayArray` and `TestBinaryViewCompareKernel.ArrayScalar` with cases covering prefix mismatch, out-of-line equality, null bytes, and long strings. ### Are these changes tested? Yes, extended existing parameterized tests in `scalar_compare_test.cc`. ### Are there any user-facing changes? No. ### Was AI used for this PR? AI was used to assist with kernel registration and testing under human direction. **PR code and description written by:** - [ ] Human - [x] AI **Reviewed before submission by:** - [x] Human - [x] AI - [ ] Not reviewed * GitHub Issue: apache#55254
3660d80 to
de62926
Compare
…uality kernels - Extract shared ViewArrayCompareBinaryScalarEqual helper to decouple View and String kernel structs. - Optimize variadic payload comparisons by skipping the verified 4-byte prefix. - Use stateless indexed offset traversal in ViewCompareStringEqual::ArrayArray. - Clean up boolean expressions and add Doxygen API documentation in binary_view_util.h. - Add asymmetric slice test coverage in scalar_compare_test.cc.
|
Should be add "OG baseline" to the comparison (i.e. cast + comparison) so we are discouraged by few perf "losses"? p.s. what sort of feedback are you looking for with this PR? |
|
@dmitry-chirkov-dremio I updated the earlier benchmark table with the OG baseline (cast + comparison). Also letting you know that #54668 has been merged and is the active baseline. Regarding feedback for this PR:
|
|
@Awesome06 what is your personal recommendation? |
…lti-buffer tests - Early return on BaseBinaryScalar length exceeding INT32_MAX to prevent 32-bit truncation in ViewArrayCompareBinaryScalarEqual. - Add test coverage for inlined prefix collisions (abcdefgh vs abcdefgX) in ArrayArray and ArrayScalar compare kernels. - Add MultiplePayloadBuffers test case verifying cross-buffer comparisons and buffer index dereferencing.
|
@dmitry-chirkov-dremio Yes, I think it is well worth it. Baseline was simple only because it used the generic executor and ignored the 4-byte prefix. In real workloads (selective filters), 90%+ of rows are mismatches or short inline strings, where Option A is 4.7x faster on scalars, 2x on mismatches, and 1.5x on inline strings. The ~14% drop only hits when 100% of rows are identical >12 B strings, and even there it remains 3x faster than the OG baseline. Trading that corner-case for 4.7x on selective filters fulfills why we use StringView, without needing runtime heuristics like Option B. |
|
Sorry, I'm slow today. I got lost in options A and B. If yes, could you clarify the wins/losses of A vs B again? In your earlier comment you seem to have implied you prefer A yourself, no? Or is that the impression you got from me? |
What Each Option Means
Why Option A is the Right Path Forward
|
dmitry-chirkov-dremio
left a comment
There was a problem hiding this comment.
Thanks, clear now. I lean toward A. Please summarize the gains and the slowdown against the merged baseline in the PR description.
|
Updated the PR description with the benchmark comparison and trade-off summary against the #55171 baseline. |
|
|
1 similar comment
|
|
|
|
|
Hey @adamreeve @pitrou, There seems to be noticeable improvements, so i am hoping for a review on it. @dmitry-chirkov-dremio could you mark this PR as reviewed? |
adamreeve
left a comment
There was a problem hiding this comment.
Thanks @Awesome06, this looks like a worthwhile improvement to me. I agree that the small slowdown comparing long strings with equal prefix seems worthwhile for the speed ups in all the other cases. I just have some minor suggestions to improve readability.
…fix size in StringView equality kernels - Add static_assert for BinaryViewType::kPrefixSize == sizeof(uint32_t) in EqualBinaryViewString and ViewCompareStringEqual. - Add static_assert for 64-bit size_and_prefix representation in ViewArrayCompareBinaryScalarEqual. - Rename cryptic variables (s_sp, v_sp, s_inline, s_inlined) to self-documenting names (scalar_size_and_prefix, view_size_and_prefix, scalar_is_inline, scalar_inlined). - Improve parameter and variable naming in EqualBinaryViewString.
|
Thanks for the review @adamreeve! Pushed an update addressing both suggestions:
|
|
This is a lot of hand-written (well, AI-written, but with human maintainers down the read) code for a single comparison kernel. I'm not convinced the performance uptake is worth the additional maintenance effort. What do you think @zanmato1984 ? |
|
Fair point on the maintenance overhead @pitrou. If the ~250 lines feel too heavy for equality alone, I can attempt to cut this diff down to fewer lines. Most of the boilerplate comes from separate Regarding broader scope: we had to hand-roll loops here because |
That sounds interesting indeed. Hopefully we can do this while still making it easy to write BinaryView-supporting kernels? |
|
Yes, preserving that simplicity is key. The idea is to keep the standard
All looping, null bitmaps, and scalar broadcasting remain inside the applicator. |
|
I could add couple of code comments... (The oversized large_binary guard still needs a regression test and the mixed array test skips buffer 1 because the lengths differ) I’m leaning toward stopping here though. This was worth trying. Thanks you for entertaining the idea. View/view got faster, some mixed comparisons got slower, even for short strings. I don’t think the gains justify the extra code. I’d keep #55171 as it is. |
Am I misunderstanding the results here, or did you do your own benchmarks for this @dmitry-chirkov-dremio? From the results above, it looks like the only case that got slower between the baseline and this PR (option A) was |
No, I did not. And yes, I might have gotten lost in "baseline vs option X" 😅 hence the fallback to "complexity argument" i.e "~14-17% slowdown on identical out-of-line strings" is what I keep coming back to but that's "vs baseline" and "baseline" is not "what we had before"... I'm gonna remove myself from this conversation now and go catch a turkey or something. |
|
@pitrou @adamreeve So what are your opinions on the approach to take
|
|
We could leave this open for now and see what the applicator level change looks like in a separate PR before deciding which approach to go with, if any? |
|
I opened #55801 to scope the first step to the applicator layer for PR #55802 implements this along with the |
Rationale for this change
In #55171, direct comparison kernels were added between StringView/BinaryView and offset-based string types. Those kernels relied on
applicator::ScalarBinarywithArrayIterator<BinaryViewType>, which eagerly callsutil::FromBinaryViewand resolves variadic payload pointers for every element regardless of match outcome.As discussed in #55254, equality comparisons (
equal,not_equal) can check the view's 4-byte inline prefix and string length before accessing payload buffers, rejecting mismatches early.What changes are included in this PR?
util::EqualBinaryViewString: Added inarrow/util/binary_view_util.hto compare aBinaryViewType::c_typewith contiguous string data, checking length and 4-byte prefix before dereferencing view variadic buffers.ViewCompareViewEqualandViewCompareStringEqualinscalar_compare.cc, replacing eager iterator resolution forequalandnot_equal.TestBinaryViewCompareKernel.ArrayArrayandTestBinaryViewCompareKernel.ArrayScalarwith cases covering prefix mismatch, out-of-line equality, null bytes, and long strings.Performance results (vs merged #55171 baseline)
memcmp.memcmp.Are these changes tested?
Yes, extended existing parameterized tests in
scalar_compare_test.cc.Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by:
Closes #55254