-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#23189) * shrink batches when over 80% of the space is wasted (#23066) * shrink batches when over 80% of the space is wasted (cherry picked from commit 83d31c9) # Conflicts: # core/benches/sigverify_stage.rs # core/src/sigverify_stage.rs # perf/src/sigverify.rs * fixup! Co-authored-by: anatoly yakovenko <[email protected]>
- Loading branch information
1 parent
41bbc11
commit 3fd78ac
Showing
4 changed files
with
458 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#![allow(clippy::integer_arithmetic)] | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
|
||
use { | ||
rand::prelude::*, | ||
solana_perf::{ | ||
packet::{to_packet_batches, PacketBatch, PACKETS_PER_BATCH}, | ||
sigverify, | ||
}, | ||
test::Bencher, | ||
}; | ||
|
||
const NUM_PACKETS: usize = 1024 * 4; | ||
|
||
fn test_packet_with_size(size: usize, rng: &mut ThreadRng) -> Vec<u8> { | ||
// subtract 8 bytes because the length will get serialized as well | ||
(0..size.checked_sub(8).unwrap()) | ||
.map(|_| rng.gen()) | ||
.collect() | ||
} | ||
|
||
fn do_bench_shrink_packets(bencher: &mut Bencher, mut batches: Vec<PacketBatch>) { | ||
// verify packets | ||
bencher.iter(|| { | ||
let _ans = sigverify::shrink_batches(&mut batches); | ||
batches.iter_mut().for_each(|b| { | ||
b.packets | ||
.iter_mut() | ||
.for_each(|p| p.meta.set_discard(thread_rng().gen())) | ||
}); | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_diff_small_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(128, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
|
||
do_bench_shrink_packets(bencher, batches); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_diff_big_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(1024, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
|
||
do_bench_shrink_packets(bencher, batches); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_count_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let mut batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(128, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
batches.iter_mut().for_each(|b| { | ||
b.packets | ||
.iter_mut() | ||
.for_each(|p| p.meta.set_discard(thread_rng().gen())) | ||
}); | ||
|
||
bencher.iter(|| { | ||
let _ = sigverify::count_valid_packets(&batches); | ||
}); | ||
} |
Oops, something went wrong.