From 015058e0b7c7895ac5cfaa5a683777ef1e78bdf9 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 25 Jan 2021 13:27:47 +0900 Subject: [PATCH] Reduce ~2 GBs mem by avoiding another overalloc. (#14806) * Reduce few GBs mem by avoiding another overalloc. * Use x.len() for the last item from chunks() --- perf/src/packet.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/perf/src/packet.rs b/perf/src/packet.rs index d257f2e7c..1c4210c44 100644 --- a/perf/src/packet.rs +++ b/perf/src/packet.rs @@ -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) } } @@ -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); @@ -61,7 +65,7 @@ impl Packets { pub fn to_packets_chunked(xs: &[T], chunks: usize) -> Vec { 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");