Skip to content

[v25.3.x] iobuf: fix operator<=> and operator== for string_view comparisons#29477

Merged
rockwotj merged 3 commits intoredpanda-data:v25.3.xfrom
vbotbuildovich:backport-pr-29461-v25.3.x-402
Jan 31, 2026
Merged

[v25.3.x] iobuf: fix operator<=> and operator== for string_view comparisons#29477
rockwotj merged 3 commits intoredpanda-data:v25.3.xfrom
vbotbuildovich:backport-pr-29461-v25.3.x-402

Conversation

@vbotbuildovich
Copy link
Copy Markdown
Collaborator

Backport of PR #29461

The previous implementation had inverted stop_iteration logic - it
stopped when the comparison was equal and continued when not equal,
causing incorrect results when the first fragment comparison determined
the ordering.

Replaced iterator_consumer pattern with a simpler for-each loop over
fragments. Added comprehensive tests covering multi-fragment comparisons.

Benchmark results (instructions, runtime):
- sv_cmp_0000: 49 -> 36 inst (-27%), 2.28ns -> 2.16ns (-5%)
- sv_cmp_0001: 87 -> 64 inst (-26%), 3.61ns -> 3.17ns (-12%)
- sv_cmp_1024 (different): 121 -> 60 inst (-50%), 4.98ns -> 3.44ns (-31%)
- sv_cmp_1024 (same): 256 -> 214 inst (-16%), 10.37ns -> 9.41ns (-9%)

Runtime improvements are consistent with instruction count reductions.

(cherry picked from commit aad9cff)
Simplify operator== by delegating to the fixed operator<=> implementation.
This reduces code duplication and ensures consistent comparison behavior.

Benchmark results (instructions, runtime):
- sv_eq_0000: 38 -> 30 inst (-21%), 2.30ns -> 1.95ns (-15%)
- sv_eq_0001: 83 -> 58 inst (-30%), 3.61ns -> 2.96ns (-18%)
- sv_eq_1024 (different): 80 -> 57 inst (-29%), 3.70ns -> 3.25ns (-12%)
- sv_eq_1024 (same): 247 -> 209 inst (-15%), 10.50ns -> 9.46ns (-10%)

Runtime improvements are consistent with instruction count reductions.

(cherry picked from commit 30220a4)
Add sv_eq_* and sv_cmp_* benchmark cases to measure performance of
iobuf::operator== and operator<=> against string_view. Uses a
templated cmp_bench function with rhs_type parameter to support
both iobuf-vs-iobuf and iobuf-vs-string_view comparisons.

Tests both single-fragment and fragmented iobufs at sizes 0, 1, 1024.

(cherry picked from commit 5752502)
@vbotbuildovich vbotbuildovich added this to the v25.3.x-next milestone Jan 30, 2026
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label Jan 30, 2026
@rockwotj rockwotj merged commit 192ecff into redpanda-data:v25.3.x Jan 31, 2026
19 checks passed
@piyushredpanda piyushredpanda modified the milestones: v25.3.x-next, v25.3.7 Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/redpanda kind/backport PRs targeting a stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants