Skip to content

Commit

Permalink
Use VecDeque instead of Vec in sigverify stage (#22538) (#22550)
Browse files Browse the repository at this point in the history
avoid bad performance of remove(0) for a single sender

(cherry picked from commit 4944340)

# Conflicts:
#	core/src/sigverify_stage.rs

Co-authored-by: sakridge <[email protected]>
  • Loading branch information
mergify[bot] and sakridge authored Jan 19, 2022
1 parent 2546ef4 commit 2b87d99
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(test)]
#![allow(clippy::integer_arithmetic)]

extern crate solana_core;
extern crate test;
Expand All @@ -22,8 +23,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 @@ -32,7 +32,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 @@ -60,6 +60,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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
solana_sdk::timing,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError},
std::{
collections::HashMap,
collections::{HashMap, VecDeque},
sync::mpsc::{Receiver, RecvTimeoutError},
thread::{self, Builder, JoinHandle},
time::Instant,
Expand Down Expand Up @@ -145,17 +145,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 2b87d99

Please sign in to comment.