Skip to content

Commit 747fbc2

Browse files
authored
tp: make FlexVector::shrink_to_fit a no-op at minimal capacity (#7198)
shrink_to_fit unconditionally reallocated and copied the storage even when capacity was already the smallest legal size for the current element count. Dataframe::Finalize calls it on every column of every built dataframe, so each finalize silently copied all column storage. That copy also defeats any downstream design that wants to share or move finalized column storage instead of duplicating it. Return early when the aligned size already equals capacity, making the call free in the common already-minimal case.
1 parent 386d870 commit 747fbc2

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/trace_processor/core/util/flex_vector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ class FlexVector {
188188
// Shrinks the memory allocated by the vector to be as small as possible while
189189
// still maintaining the invariants of the class.
190190
void shrink_to_fit() {
191+
if (base::AlignUp(size_, kCapacityMultiple) == capacity()) {
192+
return;
193+
}
191194
if (size_ == 0) {
192195
slab_ = Slab<T>::Alloc(0);
193196
} else {

0 commit comments

Comments
 (0)