Skip to content

Commit

Permalink
Use VecDeque instead of Vec in sigverify stage (#22538)
Browse files Browse the repository at this point in the history
avoid bad performance of remove(0) for a single sender
  • Loading branch information
sakridge committed Jan 17, 2022
1 parent 2d94e6e commit 4944340
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 13 additions & 3 deletions core/benches/sigverify_stage.rs
@@ -1,4 +1,5 @@
#![feature(test)]
#![allow(clippy::integer_arithmetic)]

extern crate solana_core;
extern crate test;
Expand All @@ -19,8 +20,7 @@ use {
test::Bencher,
};

#[bench]
fn bench_packet_discard(bencher: &mut Bencher) {
fn run_bench_packet_discard(num_ips: usize, bencher: &mut Bencher) {
solana_logger::setup();
let len = 30 * 1000;
let chunk_size = 1024;
Expand All @@ -29,7 +29,7 @@ fn bench_packet_discard(bencher: &mut Bencher) {

let mut total = 0;

let ips: Vec<_> = (0..10_000)
let ips: Vec<_> = (0..num_ips)
.into_iter()
.map(|_| {
let mut addr = [0u16; 8];
Expand Down Expand Up @@ -57,6 +57,16 @@ fn bench_packet_discard(bencher: &mut Bencher) {
});
}

#[bench]
fn bench_packet_discard_many_senders(bencher: &mut Bencher) {
run_bench_packet_discard(1000, bencher);
}

#[bench]
fn bench_packet_discard_single_sender(bencher: &mut Bencher) {
run_bench_packet_discard(1, bencher);
}

#[bench]
fn bench_sigverify_stage(bencher: &mut Bencher) {
solana_logger::setup();
Expand Down
10 changes: 5 additions & 5 deletions core/src/sigverify_stage.rs
Expand Up @@ -13,7 +13,7 @@ use {
solana_sdk::timing,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError},
std::{
collections::HashMap,
collections::{HashMap, VecDeque},
thread::{self, Builder, JoinHandle},
time::Instant,
},
Expand Down Expand Up @@ -144,17 +144,17 @@ impl SigVerifyStage {
for (packet_index, packets) in batch.packets.iter().enumerate() {
let e = received_ips
.entry(packets.meta.addr().ip())
.or_insert_with(Vec::new);
e.push((batch_index, packet_index));
.or_insert_with(VecDeque::new);
e.push_back((batch_index, packet_index));
}
}
let mut batch_len = 0;
while batch_len < max_packets {
for (_ip, indexes) in received_ips.iter_mut() {
if !indexes.is_empty() {
indexes.remove(0);
indexes.pop_front();
batch_len += 1;
if batch_len >= MAX_SIGVERIFY_BATCH {
if batch_len >= max_packets {
break;
}
}
Expand Down

0 comments on commit 4944340

Please sign in to comment.