Remove potentially too costly Packets::default() (#14821)
* Remove potentially too costly Packets::default() * Fix test... * Restore Packets::default() * Restore Packets::default() more
This commit is contained in:
parent
8993ac0c74
commit
d6873b82ab
|
@ -1121,7 +1121,7 @@ mod tests {
|
|||
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
||||
get_tmp_ledger_path,
|
||||
};
|
||||
use solana_perf::packet::to_packets;
|
||||
use solana_perf::packet::to_packets_chunked;
|
||||
use solana_sdk::{
|
||||
instruction::InstructionError,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -1292,7 +1292,7 @@ mod tests {
|
|||
let tx_anf = system_transaction::transfer(&keypair, &to3, 1, start_hash);
|
||||
|
||||
// send 'em over
|
||||
let packets = to_packets(&[tx_no_ver, tx_anf, tx]);
|
||||
let packets = to_packets_chunked(&[tx_no_ver, tx_anf, tx], 3);
|
||||
|
||||
// glad they all fit
|
||||
assert_eq!(packets.len(), 1);
|
||||
|
@ -1368,7 +1368,7 @@ mod tests {
|
|||
let tx =
|
||||
system_transaction::transfer(&mint_keypair, &alice.pubkey(), 2, genesis_config.hash());
|
||||
|
||||
let packets = to_packets(&[tx]);
|
||||
let packets = to_packets_chunked(&[tx], 1);
|
||||
let packets = packets
|
||||
.into_iter()
|
||||
.map(|packets| (packets, vec![1u8]))
|
||||
|
@ -1379,7 +1379,7 @@ mod tests {
|
|||
// Process a second batch that uses the same from account, so conflicts with above TX
|
||||
let tx =
|
||||
system_transaction::transfer(&mint_keypair, &alice.pubkey(), 1, genesis_config.hash());
|
||||
let packets = to_packets(&[tx]);
|
||||
let packets = to_packets_chunked(&[tx], 1);
|
||||
let packets = packets
|
||||
.into_iter()
|
||||
.map(|packets| (packets, vec![1u8]))
|
||||
|
|
|
@ -825,7 +825,7 @@ mod tests {
|
|||
use bincode::serialized_size;
|
||||
info!("max vote size {}", serialized_size(&vote_tx).unwrap());
|
||||
|
||||
let msgs = packet::to_packets(&[vote_tx]); // panics if won't fit
|
||||
let msgs = packet::to_packets_chunked(&[vote_tx], 1); // panics if won't fit
|
||||
|
||||
assert_eq!(msgs.len(), 1);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
extern crate test;
|
||||
|
||||
use solana_perf::packet::to_packets;
|
||||
use solana_perf::packet::to_packets_chunked;
|
||||
use solana_perf::recycler::Recycler;
|
||||
use solana_perf::sigverify;
|
||||
use solana_perf::test_tx::test_tx;
|
||||
|
@ -13,7 +13,7 @@ fn bench_sigverify(bencher: &mut Bencher) {
|
|||
let tx = test_tx();
|
||||
|
||||
// generate packet vector
|
||||
let batches = to_packets(&std::iter::repeat(tx).take(128).collect::<Vec<_>>());
|
||||
let batches = to_packets_chunked(&std::iter::repeat(tx).take(128).collect::<Vec<_>>(), 128);
|
||||
|
||||
let recycler = Recycler::default();
|
||||
let recycler_out = Recycler::default();
|
||||
|
@ -28,7 +28,7 @@ fn bench_get_offsets(bencher: &mut Bencher) {
|
|||
let tx = test_tx();
|
||||
|
||||
// generate packet vector
|
||||
let batches = to_packets(&std::iter::repeat(tx).take(1024).collect::<Vec<_>>());
|
||||
let batches = to_packets_chunked(&std::iter::repeat(tx).take(1024).collect::<Vec<_>>(), 1024);
|
||||
|
||||
let recycler = Recycler::default();
|
||||
// verify packets
|
||||
|
|
|
@ -11,18 +11,11 @@ pub const PACKETS_PER_BATCH: usize = 256;
|
|||
pub const NUM_RCVMMSGS: usize = 128;
|
||||
pub const PACKETS_BATCH_SIZE: usize = PACKETS_PER_BATCH * PACKET_DATA_SIZE;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Packets {
|
||||
pub packets: PinnedVec<Packet>,
|
||||
}
|
||||
|
||||
//auto derive doesn't support large arrays
|
||||
impl Default for Packets {
|
||||
fn default() -> Packets {
|
||||
Self::with_capacity(NUM_RCVMMSGS)
|
||||
}
|
||||
}
|
||||
|
||||
pub type PacketsRecycler = Recycler<PinnedVec<Packet>>;
|
||||
|
||||
impl Packets {
|
||||
|
@ -75,6 +68,7 @@ pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<Packets>
|
|||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn to_packets<T: Serialize>(xs: &[T]) -> Vec<Packets> {
|
||||
to_packets_chunked(xs, NUM_PACKETS)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! The `packet` module defines data structures and methods to pull data from the network.
|
||||
use crate::recvmmsg::{recv_mmsg, NUM_RCVMMSGS};
|
||||
pub use solana_perf::packet::{
|
||||
limited_deserialize, to_packets, to_packets_chunked, Packets, PacketsRecycler, NUM_PACKETS,
|
||||
limited_deserialize, to_packets_chunked, Packets, PacketsRecycler, NUM_PACKETS,
|
||||
PACKETS_BATCH_SIZE, PACKETS_PER_BATCH,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue