Skip to content

Commit

Permalink
Fix allocation behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru committed Jul 1, 2024
1 parent 5f7ff7c commit 8cfa559
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/ore/src/flatcontainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ mod lgalloc {
#[inline]
fn clear(&mut self) {
self.slices.clear();
self.offsets.clear();
self.offsets.push(0);
}

#[inline]
Expand Down
14 changes: 9 additions & 5 deletions src/ore/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,18 @@ mod vec {
}
}

const MIN_NON_ZERO_CAP: usize = if std::mem::size_of::<T>() == 1 {
8
} else if std::mem::size_of::<T>() <= 1024 {
4
} else {
1
};

/// Grow the array to at least `new_len` elements. Reallocates the underlying storage.
fn grow(&mut self, new_len: usize) {
let new_capacity = std::cmp::max(self.capacity() * 2, new_len);
println!(
"Reallocating {} -> {}, requested {new_len}",
self.capacity(),
new_capacity
);
let new_capacity = std::cmp::max(new_capacity, Self::MIN_NON_ZERO_CAP);
let mut new_vec = LgAllocVec::with_capacity(new_capacity);

let src_ptr = self.elements.as_ptr();
Expand Down

0 comments on commit 8cfa559

Please sign in to comment.