Skip to content

GH-55801: [C++][Compute] Prefix-aware BinaryView/StringView execution for equal and not_equal - #55802

Open
Awesome06 wants to merge 2 commits into
apache:mainfrom
Awesome06:gh-55254-binaryview-applicator
Open

Awesome06 wants to merge 2 commits into
apache:mainfrom
Awesome06:gh-55254-binaryview-applicator

Conversation

@Awesome06

@Awesome06 Awesome06 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

ArrayIterator<Type, enable_if_binary_view_like<Type>> in codegen_internal.h unconditionally calls util::FromBinaryView on every element before invoking Op::Call. For equal and not_equal on BinaryView / StringView (including the mixed BinaryView vs BaseBinary / LargeBinary kernels from #55171), that dereferences out-of-line variadic buffers even when the 16-byte descriptor (size and 4-byte inline prefix) mismatches.

Adding an opt-in CallView dispatch path in the applicators avoids eager buffer dereferences on mismatch while keeping GetViewType<BinaryViewType>::T = std::string_view and existing Op::Call kernels untouched.

What changes are included in this PR?

  • binary_view_util.h: Added BinaryViewAccessor, PinnedBinaryScalar (guarding null scalars and > INT32_MAX scalar lengths, with endian-safe memcpy for size_and_prefix), EqualBinaryViewString, and EqualBinaryViewValue overloads constrained by IsBinaryViewOperand.
  • codegen_internal.h: Added ViewDescriptorIterator, ViewScalarUnboxer, VisitBinaryViewValuesInline, VisitTwoBinaryViewValuesInline, and CallView dispatch in ScalarUnary, ScalarUnaryNotNullStateful, ScalarBinary, and ScalarBinaryNotNullStateful.
  • scalar_compare.cc: Opted Equal and NotEqual into CallView via util::EqualBinaryViewValue.
  • codegen_internal_test.cc & scalar_compare_test.cc: Added applicator tests (Call fallback, CallView early rejection with sentinel out-of-range buffer indices, sliced arrays, null/oversized scalars) and expanded TestBinaryViewCompareKernel.
  • scalar_compare_benchmark.cc: Added StringView equality benchmarks (inline, out-of-line, shared-prefix, array-scalar, and mixed StringView vs String).

Benchmarks

Measured with arrow-compute-scalar-compare-benchmark (65,536 rows, median of 5 repetitions, Release GCC 16.2.0 -O3 -DNDEBUG, -DARROW_SIMD_LEVEL=NONE -DARROW_RUNTIME_SIMD_LEVEL=NONE) comparing upstream/main (dd456e0) against this branch (bde2592):

Benchmark Nulls Baseline Prefix-Aware (CallView) Speedup
EqualArrayArrayStringView 0% 1360.21 µs 159.04 µs 8.55x
EqualArrayArrayStringView 1% 1227.68 µs 156.93 µs 7.82x
EqualArrayScalarStringView 0% 616.04 µs 87.89 µs 7.01x
EqualArrayScalarStringView 1% 669.64 µs 89.98 µs 7.44x
EqualArrayArrayStringViewInline 0% 285.99 µs 136.72 µs 2.09x
EqualArrayArrayStringViewInline 1% 327.85 µs 141.60 µs 2.32x
EqualArrayArrayStringViewOutOfLine 0% 251.10 µs 132.53 µs 1.89x
EqualArrayArrayStringViewOutOfLine 1% 266.84 µs 134.97 µs 1.98x
EqualArrayScalarStringViewOutOfLine 0% 219.73 µs 85.79 µs 2.56x
EqualArrayScalarStringViewOutOfLine 1% 207.16 µs 88.94 µs 2.33x
EqualArrayArrayStringViewSharedPrefix 0% 871.93 µs 711.50 µs 1.23x
EqualArrayArrayStringViewSharedPrefix 1% 851.00 µs 714.98 µs 1.19x
EqualArrayArrayStringViewString 0% 276.22 µs 239.96 µs 1.15x
EqualArrayArrayStringViewString 1% 262.28 µs 251.09 µs 1.04x
EqualArrayScalarStringViewString 0% 208.58 µs 89.98 µs 2.32x
EqualArrayScalarStringViewString 1% 217.63 µs 90.62 µs 2.40x

Are these changes tested?

Yes. Added unit tests in codegen_internal_test.cc and scalar_compare_test.cc, and ran arrow-compute-kernel-utility-test, arrow-compute-scalar-math-test, arrow-compute-scalar-cast-test, arrow-compute-scalar-if-else-test, and arrow-compute-scalar-utility-test.

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI lite review requested due to automatic review settings November 26, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@Awesome06 Awesome06 changed the title Gh 55254 binaryview applicator GH-55801: [C++][Compute] Prefix-aware BinaryView/StringView execution for equal and not_equal Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants