Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(filecoin-proofs): speed up Fr32Reader #1341

Merged
merged 4 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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