Skip to content

bench: Improve benchmarks for left, right - #26026

Merged
neilconway merged 1 commit into
apache:mainfrom
neilconway:neilc/bench-left-right-variable
Oct 5, 2026
Merged

neilconway merged 1 commit into
apache:mainfrom
neilconway:neilc/bench-left-right-variable

Conversation

@neilconway

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

The left/right benchmarks had some shortcomings:

  • The Utf8 cases used fixed-length (32-byte) strings, whereas Utf8View used variable-length strings. Drawing the inputs from different distributions made it hard to compare results between the two data types; also, using fixed-length strings results in unrealistically good branch prediction, which can hide performance problems on typical real-world data.
  • All the benchmarks tested a variably-sized result length, which is not super common in practice; left(s, k) for a constant k is more common.
  • The UDF's return type was hard-coded to Utf8View, so the benchmarks panicked in debug mode.

What changes are included in this PR?

  • Only test variably-sized strings for both data types
  • Use fixed result length for all benchmark cases except one
  • Add benchmark cases for long strings with small n, negative n, and for n exceeding the input string length
  • Fix UDF return type

What is the testing strategy for this PR?

Only benchmark changes.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the functions Changes to functions implementation label Oct 4, 2026
@neilconway

Copy link
Copy Markdown
Contributor Author

FYI @Jefffrey @theirix @xudong963

@codecov-commenter

codecov-commenter commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.66%. Comparing base (9547b09) to head (b86d26b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #26026    +/-   ##
========================================
  Coverage   82.65%   82.66%            
========================================
  Files        1147     1147            
  Lines      446087   446357   +270     
  Branches   446087   446357   +270     
========================================
+ Hits       368721   368971   +250     
- Misses      54980    54996    +16     
- Partials    22386    22390     +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The Utf8 inputs were all exactly 32 bytes, while the Utf8View inputs
used a different length distribution, so the two array types were not
benchmarked on the same data. Fixed-length inputs also make per-row
work that depends on the input length, such as an ASCII check over the
whole string, perfectly predictable, so it looks nearly free. And every
case passed `n` as an array cycling through a short range, although `n`
is usually a literal.

Generate variable-length inputs for every case and build the Utf8 and
Utf8View arrays from the same strings. Pass `n` as a scalar, and add a
case with a different random `n` per row. Add cases for short results
from long inputs, for `n` exceeding the input length, and for negative
`n`.

Also derive the return field from the function instead of always using
Utf8View. Since apache#23330, `left` and `right` return Utf8 for Utf8 input,
and the mismatch fails the check in `ScalarUDF::invoke_with_args` when
debug assertions are enabled.
@neilconway
neilconway force-pushed the neilc/bench-left-right-variable branch from a412ae8 to b86d26b Compare October 4, 2026 17:26
@neilconway
neilconway added this pull request to the merge queue Oct 5, 2026
Merged via the queue into apache:main with commit 80be3e8 Oct 5, 2026
42 checks passed
@neilconway
neilconway deleted the neilc/bench-left-right-variable branch October 5, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants