Slightly refactor start_verify_transactions to avoid an unnecessary loop through the vector (#25559)
* Small refactoring to remove an unnecessary loop through the vector
This commit is contained in:
parent
1fda5110af
commit
178eba4912
|
@ -35,10 +35,7 @@ use {
|
||||||
std::{
|
std::{
|
||||||
cmp,
|
cmp,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
sync::{
|
sync::{Arc, Mutex, Once},
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Arc, Mutex, Once,
|
|
||||||
},
|
|
||||||
thread::{self, JoinHandle},
|
thread::{self, JoinHandle},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
},
|
},
|
||||||
|
@ -473,24 +470,6 @@ pub fn start_verify_transactions(
|
||||||
let entries = verify_transactions(entries, Arc::new(verify_func));
|
let entries = verify_transactions(entries, Arc::new(verify_func));
|
||||||
match entries {
|
match entries {
|
||||||
Ok(entries) => {
|
Ok(entries) => {
|
||||||
let num_transactions: usize = entries
|
|
||||||
.iter()
|
|
||||||
.map(|entry: &EntryType| -> usize {
|
|
||||||
match entry {
|
|
||||||
EntryType::Transactions(transactions) => transactions.len(),
|
|
||||||
EntryType::Tick(_) => 0,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
if num_transactions == 0 {
|
|
||||||
return Ok(EntrySigVerificationState {
|
|
||||||
verification_status: EntryVerificationStatus::Success,
|
|
||||||
entries: Some(entries),
|
|
||||||
device_verification_data: DeviceSigVerificationData::Cpu(),
|
|
||||||
gpu_verify_duration_us: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
let entry_txs: Vec<&SanitizedTransaction> = entries
|
let entry_txs: Vec<&SanitizedTransaction> = entries
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|entry_type| match entry_type {
|
.filter_map(|entry_type| match entry_type {
|
||||||
|
@ -499,22 +478,30 @@ pub fn start_verify_transactions(
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let total_packets = AtomicUsize::new(0);
|
|
||||||
|
if entry_txs.is_empty() {
|
||||||
|
return Ok(EntrySigVerificationState {
|
||||||
|
verification_status: EntryVerificationStatus::Success,
|
||||||
|
entries: Some(entries),
|
||||||
|
device_verification_data: DeviceSigVerificationData::Cpu(),
|
||||||
|
gpu_verify_duration_us: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut packet_batches = entry_txs
|
let mut packet_batches = entry_txs
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.chunks(PACKETS_PER_BATCH)
|
.chunks(PACKETS_PER_BATCH)
|
||||||
.map(|slice| {
|
.map(|slice| {
|
||||||
let vec_size = slice.len();
|
let vec_size = slice.len();
|
||||||
total_packets.fetch_add(vec_size, Ordering::Relaxed);
|
|
||||||
let mut packet_batch = PacketBatch::new_with_recycler(
|
let mut packet_batch = PacketBatch::new_with_recycler(
|
||||||
verify_recyclers.packet_recycler.clone(),
|
verify_recyclers.packet_recycler.clone(),
|
||||||
vec_size,
|
vec_size,
|
||||||
"entry-sig-verify",
|
"entry-sig-verify",
|
||||||
);
|
);
|
||||||
// We use set_len here instead of resize(num_transactions, Packet::default()), to save
|
// We use set_len here instead of resize(vec_size, Packet::default()), to save
|
||||||
// memory bandwidth and avoid writing a large amount of data that will be overwritten
|
// memory bandwidth and avoid writing a large amount of data that will be overwritten
|
||||||
// soon afterwards. As well, Packet::default() actually leaves the packet data
|
// soon afterwards. As well, Packet::default() actually leaves the packet data
|
||||||
// uninitialized anyway, so the initilization would simply write junk into
|
// uninitialized, so the initialization would simply write junk into
|
||||||
// the vector anyway.
|
// the vector anyway.
|
||||||
unsafe {
|
unsafe {
|
||||||
packet_batch.set_len(vec_size);
|
packet_batch.set_len(vec_size);
|
||||||
|
@ -537,6 +524,7 @@ pub fn start_verify_transactions(
|
||||||
|
|
||||||
let tx_offset_recycler = verify_recyclers.tx_offset_recycler;
|
let tx_offset_recycler = verify_recyclers.tx_offset_recycler;
|
||||||
let out_recycler = verify_recyclers.out_recycler;
|
let out_recycler = verify_recyclers.out_recycler;
|
||||||
|
let num_packets = entry_txs.len();
|
||||||
let gpu_verify_thread = thread::spawn(move || {
|
let gpu_verify_thread = thread::spawn(move || {
|
||||||
let mut verify_time = Measure::start("sigverify");
|
let mut verify_time = Measure::start("sigverify");
|
||||||
sigverify::ed25519_verify(
|
sigverify::ed25519_verify(
|
||||||
|
@ -544,7 +532,7 @@ pub fn start_verify_transactions(
|
||||||
&tx_offset_recycler,
|
&tx_offset_recycler,
|
||||||
&out_recycler,
|
&out_recycler,
|
||||||
false,
|
false,
|
||||||
total_packets.load(Ordering::Relaxed),
|
num_packets,
|
||||||
);
|
);
|
||||||
let verified = packet_batches
|
let verified = packet_batches
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in New Issue