Repository navigation
core/chunked_vector: improve move construction and assignment - #326
Merged
travisdowns merged 2 commits intoNov 4, 2026
Merged
Conversation
travisdowns
marked this pull request as ready for review
November 4, 2026 14:08
travisdowns
requested review from
StephanDollberg and
ballard26
and
a balanced review from Copilot
November 4, 2026 14:08
There was a problem hiding this comment.
🟡 Changes recommended
Construction paths invoke std::launder before a live object exists, causing undefined behavior, and move assignment lacks regression coverage for cleanup of nonempty destinations with nontrivial elements.
2 open issues
What changed in this PR
This PR reduces move-operation overhead in chunked_vector and adds benchmarks to measure the impact.
Changes:
- Move-construct members directly and implement move assignment through move construction and swap.
- Add benchmarks for move construction, move assignment, and outer-vector reallocation with trivial and nontrivial elements.
- Register the new benchmark target.
| File | Description |
|---|---|
tests/perf/CMakeLists.txt |
Registers the chunked_vector performance tests. |
tests/perf/chunked_vector_perf.cc |
Adds move-operation and reallocation benchmarks. |
include/seastar/core/chunked_vector.hh |
Revises move operations and documents moved-from behavior. |
Review effort: Balanced
StephanDollberg
previously approved these changes
Nov 4, 2026
Move-construct each member, and implement move assignment as move-construct-and-swap. This is much more efficient especially when the elements have non-trivial destructors. In a chunked_vector move benchmark (clang-22, release), per operation: move construct, out of line, nontrivial T: 4.16ns -> 2.06ns std::vector<chunked_vector> realloc: 4.58ns -> 1.15ns move assign, nontrivial T: 3.24ns -> 1.80ns
Measures move construction and move assignment of chunked_vector, with trivial (int) and nontrivial elements. Includes a case that uses a noinline helper to avoid inlining adjacent moves into the loop.
travisdowns
force-pushed
the
td-chunked-vector-move
branch
from
November 4, 2026 14:22
56018ef to
87869c7
Compare
StephanDollberg
approved these changes
Nov 4, 2026
travisdowns
enabled auto-merge (rebase)
November 4, 2026 14:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Improve chunked_vector move construction and assignment.
Release build, clang-22, 1 core, per operation:
.
The chunked_vector move constructor default-constructed the vector and then
ran the move assignment operator on it. When that operator is not inlined
(common, since it contains the loop that destroys the old contents), every
move construction pays for a call, a self-move check, a walk over the empty
destination fragments, and a full destructor of the moved-from source that
the compiler cannot prove is empty.
The first commit move-constructs each member directly and implements move
assignment as move-construct-and-swap. Both now inline, and the source's
destructor folds away after a move.
The second commit adds tests/perf/chunked_vector_perf.cc, which measures
move construction (inline loop, through a noinline helper, and as
std::vector<chunked_vector> reallocation) and move assignment, with int
and with an element that has an out-of-line destructor.
Tested: chunked_vector_test and chunked_vector_async_test pass in dev mode.