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()
This commit is contained in:
parent
e1021d9f83
commit
015058e0b7
|
@ -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<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");
|
||||
|
|
Loading…
Reference in New Issue