Skip to content

Commit

Permalink
Reduce ~2 GBs mem by avoiding another overalloc. (#14806) (#14819)
Browse files Browse the repository at this point in the history
* Reduce few GBs mem by avoiding another overalloc.

* Use x.len() for the last item from chunks()

(cherry picked from commit 015058e)

Co-authored-by: Ryo Onodera <[email protected]>
  • Loading branch information
mergify[bot] and ryoqun authored Jan 25, 2021
1 parent ea97d82 commit 5471f93
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions perf/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub struct Packets {
//auto derive doesn't support large arrays
impl Default for Packets {
fn default() -> Packets {
let packets = PinnedVec::with_capacity(NUM_RCVMMSGS);
Packets { packets }
Self::with_capacity(NUM_RCVMMSGS)
}
}

Expand All @@ -32,6 +31,11 @@ impl Packets {
Self { packets }
}

pub fn with_capacity(capacity: usize) -> Self {
let packets = PinnedVec::with_capacity(capacity);
Packets { packets }
}

pub fn new_with_recycler(recycler: PacketsRecycler, size: usize, name: &'static str) -> Self {
let mut packets = recycler.allocate(name);
packets.reserve_and_pin(size);
Expand Down Expand Up @@ -61,7 +65,7 @@ impl Packets {
pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<Packets> {
let mut out = vec![];
for x in xs.chunks(chunks) {
let mut p = Packets::default();
let mut p = Packets::with_capacity(x.len());
p.packets.resize(x.len(), Packet::default());
for (i, o) in x.iter().zip(p.packets.iter_mut()) {
Packet::populate_packet(o, None, i).expect("serialize request");
Expand Down

0 comments on commit 5471f93

Please sign in to comment.