Skip to content

Commit

Permalink
perf(filecoin-proofs): speed up Fr32Reader
Browse files Browse the repository at this point in the history
Switch to processing bit padding in blocks of 127bytes using u128s
  • Loading branch information
dignifiedquire committed Nov 5, 2020
1 parent 1038392 commit 8b9920a
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 329 deletions.
2 changes: 1 addition & 1 deletion filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ anyhow = "1.0.23"
rand_xorshift = "0.2.0"
sha2 = "0.9.1"
typenum = "1.11.2"
bitintr = "0.3.0"
gperftools = { version = "0.2", optional = true }
generic-array = "0.14.4"
structopt = "0.3.12"
Expand All @@ -45,6 +44,7 @@ indicatif = "0.15.0"
groupy = "0.3.0"
dialoguer = "0.7.1"
clap = "2.33.3"
byte-slice-cast = "1.0.0"

[dependencies.reqwest]
version = "0.10"
Expand Down
37 changes: 35 additions & 2 deletions filecoin-proofs/benches/preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{self, Read};
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion, ParameterizedBenchmark, Throughput};
use filecoin_proofs::fr32_reader::Fr32Reader;
use filecoin_proofs::{add_piece, fr32_reader::Fr32Reader, PaddedBytesAmount, UnpaddedBytesAmount};
use rand::{thread_rng, Rng};

#[cfg(feature = "cpu-profile")]
Expand Down Expand Up @@ -52,6 +52,7 @@ fn preprocessing_benchmark(c: &mut Criterion) {
let mut reader = Fr32Reader::new(io::Cursor::new(&data));
reader.read_to_end(&mut buf).expect("in memory read error");
assert!(buf.len() >= data.len());
buf.clear();
});
stop_profile();
},
Expand All @@ -63,5 +64,37 @@ fn preprocessing_benchmark(c: &mut Criterion) {
);
}

criterion_group!(benches, preprocessing_benchmark);
fn add_piece_benchmark(c: &mut Criterion) {
c.bench(
"preprocessing",
ParameterizedBenchmark::new(
"add_piece",
|b, size| {
let padded_size = PaddedBytesAmount(*size as u64);
let unpadded_size: UnpaddedBytesAmount = padded_size.into();
let data = random_data(unpadded_size.0 as usize);
let mut buf = Vec::with_capacity(*size);

start_profile(&format!("add_piece_{}", *size));
b.iter(|| {
add_piece(
io::Cursor::new(&data),
&mut buf,
unpadded_size,
&[unpadded_size][..],
)
.unwrap();
buf.clear();
});
stop_profile();
},
vec![512, 256 * 1024, 512 * 1024, 1024 * 1024, 2 * 1024 * 1024],
)
.sample_size(10)
.throughput(|s| Throughput::Bytes(*s as u64))
.warm_up_time(Duration::from_secs(1)),
);
}

criterion_group!(benches, preprocessing_benchmark, add_piece_benchmark);
criterion_main!(benches);
Loading

0 comments on commit 8b9920a

Please sign in to comment.