Skip to content

Commit

Permalink
Fix proving performance regressions
Browse files Browse the repository at this point in the history
Adds back `rayon` under `std` feature just for the `quotient_poly` module
and just for a few lines which do not make the code harder to mantain or
less readable, but provide a boost in the performance of a 25%~30%.

Resolves: #512
  • Loading branch information
CPerezz committed Apr 21, 2021
1 parent 87e333e commit 82bbfa8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dusk-bls12_381 = {version = "0.8.0-rc.0", default-features = false, features = [
dusk-jubjub = {version = "0.10.0-rc.0", default-features = false}
itertools = {version = "0.9", default-features = false}
hashbrown = {version = "0.9", default-features=false, features = ["ahash"]}
rayon = {version = "1.3", optional = true}
cfg-if = "1.0"
# Dusk related deps for WASMI serde
canonical = {version = "0.6", optional = true}
Expand All @@ -47,11 +48,19 @@ std = [
"dusk-jubjub/default",
"itertools/default",
"hashbrown/default",
"alloc"
"alloc",
"rayon"
]
alloc = ["dusk-bls12_381/alloc"]
nightly = []
trace = []
trace-print = ["trace"]
canon = ["dusk-bls12_381/canon", "dusk-jubjub/canon", "canonical", "canonical_derive"]


[profile.release]
debug = false
panic = 'abort'
lto = true
incremental = false
codegen-units = 1
29 changes: 23 additions & 6 deletions src/proof_system/quotient_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::{
};
use alloc::vec::Vec;
use dusk_bls12_381::BlsScalar;
#[cfg(feature = "std")]
use rayon::prelude::*;

/// This quotient polynomial can only be used for the standard composer
/// Each composer will need to implement their own method for computing the
Expand Down Expand Up @@ -94,8 +96,13 @@ pub(crate) fn compute(
(alpha, beta, gamma),
);

let quotient: Vec<_> = (0..domain_4n.size())
.into_iter()
#[cfg(not(feature = "std"))]
let range = (0..domain_4n.size()).into_iter();

#[cfg(feature = "std")]
let range = (0..domain_4n.size()).into_par_iter();

let quotient: Vec<_> = range
.map(|i| {
let numerator = t_1[i] + t_2[i];
let denominator = prover_key.v_h_coset_4n()[i];
Expand Down Expand Up @@ -129,8 +136,13 @@ fn compute_circuit_satisfiability_equation(
let domain_4n = EvaluationDomain::new(4 * domain.size()).unwrap();
let pi_eval_4n = domain_4n.coset_fft(pi_poly);

let t: Vec<_> = (0..domain_4n.size())
.into_iter()
#[cfg(not(feature = "std"))]
let range = (0..domain_4n.size()).into_iter();

#[cfg(feature = "std")]
let range = (0..domain_4n.size()).into_par_iter();

let t: Vec<_> = range
.map(|i| {
let wl = &wl_eval_4n[i];
let wr = &wr_eval_4n[i];
Expand Down Expand Up @@ -212,8 +224,13 @@ fn compute_permutation_checks(
compute_first_lagrange_poly_scaled(domain, alpha.square());
let l1_alpha_sq_evals = domain_4n.coset_fft(&l1_poly_alpha.coeffs);

let t: Vec<_> = (0..domain_4n.size())
.into_iter()
#[cfg(not(feature = "std"))]
let range = (0..domain_4n.size()).into_iter();

#[cfg(feature = "std")]
let range = (0..domain_4n.size()).into_par_iter();

let t: Vec<_> = range
.map(|i| {
prover_key.permutation.compute_quotient_i(
i,
Expand Down

0 comments on commit 82bbfa8

Please sign in to comment.