Skip to content

[v26.1.x] compaction: swap std::count() for cursor approach (MANUAL BACKPORT) - #30760

Merged
WillemKauf merged 2 commits into
redpanda-data:v26.1.xfrom
WillemKauf:manual-backport-30740-v26.1.x-246
Jun 11, 2026
Merged

[v26.1.x] compaction: swap std::count() for cursor approach (MANUAL BACKPORT)#30760
WillemKauf merged 2 commits into
redpanda-data:v26.1.xfrom
WillemKauf:manual-backport-30740-v26.1.x-246

Conversation

@WillemKauf

@WillemKauf WillemKauf commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Manual backport of #30740. cherry-pick conflict due to rearranged maintenance directory in dev. Dropped benchmark file additions.

Fixes #30759.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v26.1.x
  • v25.3.x
  • v25.2.x

Release Notes

Improvements

  • Optimize compaction logic, especially for large batches.

When records are removed, the filter rebuilds the batch and, for each
record, ran `std::count` over the kept-deltas vector to decide whether
to keep it, which is quadratic in the record count. Since the kept
deltas are produced by a forward scan of the same batch, they are
already in record-iteration order, so match each record with a single
advancing cursor instead.

(cherry picked from commit f1458b8)
Mirror the shared filter change in `copy_data_segment_reducer::filter`:
the rebuild path matched each record against the kept-deltas vector with
`std::count`, which is quadratic in the record count. The kept deltas are
produced by a forward scan of the same batch, so match with a single
advancing cursor instead, guarded by a `dassert` on the ordering
invariant.

(cherry picked from commit d9b0f9e)
@WillemKauf
WillemKauf force-pushed the manual-backport-30740-v26.1.x-246 branch from 02cce82 to 1b5856b Compare June 10, 2026 20:50
@WillemKauf
WillemKauf requested a review from wdberkeley June 10, 2026 20:50
@WillemKauf
WillemKauf requested a review from andrwng June 11, 2026 18:15
@WillemKauf WillemKauf changed the title [v26.1.x] compaction: swap std::count() for cursor approach and add benchmarks (MANUAL BACKPORT) [v26.1.x] compaction: swap std::count() for cursor approach (MANUAL BACKPORT) Jun 11, 2026
@WillemKauf
WillemKauf merged commit e3bbe60 into redpanda-data:v26.1.x Jun 11, 2026
24 checks passed
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