From 1c2e94f9fccb8e1de2c5a8a3ac5ce46f43775795 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Sun, 4 Sep 2022 22:46:16 -0700 Subject: [PATCH] Compute answers to FRI queries in parallel It shaved off much less than a millisecond, so it's rather negligible, but the code came out simpler so might as well. --- plonky2/src/fri/prover.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index 39e25869..71efe98a 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -149,15 +149,12 @@ fn fri_prover_query_rounds< n: usize, fri_params: &FriParams, ) -> Vec> { - (0..fri_params.config.num_query_rounds) - .map(|_| { - fri_prover_query_round::( - initial_merkle_trees, - trees, - challenger, - n, - fri_params, - ) + challenger + .get_n_challenges(fri_params.config.num_query_rounds) + .into_par_iter() + .map(|rand| { + let x_index = rand.to_canonical_u64() as usize % n; + fri_prover_query_round::(initial_merkle_trees, trees, x_index, fri_params) }) .collect() } @@ -169,13 +166,10 @@ fn fri_prover_query_round< >( initial_merkle_trees: &[&MerkleTree], trees: &[MerkleTree], - challenger: &mut Challenger, - n: usize, + mut x_index: usize, fri_params: &FriParams, ) -> FriQueryRound { let mut query_steps = Vec::new(); - let x = challenger.get_challenge(); - let mut x_index = x.to_canonical_u64() as usize % n; let initial_proof = initial_merkle_trees .iter() .map(|t| (t.get(x_index).to_vec(), t.prove(x_index)))