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

(cherry picked from commit 4944340)

# Conflicts:
#	core/src/sigverify_stage.rs
  • Loading branch information
sakridge authored and mergify-bot committed Jan 17, 2022
1 parent 96ae795 commit 51e69f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 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
12 changes: 8 additions & 4 deletions core/src/sigverify_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ use {
solana_sdk::timing,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError},
std::{
<<<<<<< HEAD
collections::HashMap,
sync::mpsc::{Receiver, RecvTimeoutError},
=======
collections::{HashMap, VecDeque},
>>>>>>> 49443406f (Use VecDeque instead of Vec in sigverify stage (#22538))
thread::{self, Builder, JoinHandle},
time::Instant,
},
Expand Down Expand Up @@ -145,17 +149,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 51e69f5

Please sign in to comment.