diff --git a/halo2_proofs/src/plonk/evaluation.rs b/halo2_proofs/src/plonk/evaluation.rs index c5a4977be4..3240ad383e 100644 --- a/halo2_proofs/src/plonk/evaluation.rs +++ b/halo2_proofs/src/plonk/evaluation.rs @@ -5,6 +5,8 @@ use crate::{ arithmetic::{parallelize, CurveAffine}, poly::{Coeff, ExtendedLagrangeCoeff, Polynomial, Rotation}, }; +#[cfg(feature = "profile")] +use ark_std::{end_timer, start_timer}; use group::ff::{Field, PrimeField, WithSmallOrderMulGroup}; use super::{shuffle, ConstraintSystem, Expression}; @@ -322,6 +324,8 @@ impl Evaluator { let l_active_row = &pk.l_active_row; let p = &pk.vk.cs.permutation; + #[cfg(feature = "profile")] + let start1 = start_timer!(|| "FFT coeff to extended for advice"); // Calculate the advice and instance cosets let advice: Vec>> = advice_polys .iter() @@ -332,6 +336,10 @@ impl Evaluator { .collect() }) .collect(); + #[cfg(feature = "profile")] + end_timer!(start1); + #[cfg(feature = "profile")] + let start2 = start_timer!(|| "FFT coeff to extended for instance"); let instance: Vec>> = instance_polys .iter() .map(|instance_polys| { @@ -341,6 +349,8 @@ impl Evaluator { .collect() }) .collect(); + #[cfg(feature = "profile")] + end_timer!(start2); let mut values = domain.empty_extended(); @@ -353,6 +363,8 @@ impl Evaluator { .zip(shuffles.iter()) .zip(permutations.iter()) { + #[cfg(feature = "profile")] + let start3 = start_timer!(|| "Custom gates"); // Custom gates multicore::scope(|scope| { let chunk_size = (size + num_threads - 1) / num_threads; @@ -381,7 +393,11 @@ impl Evaluator { }); } }); + #[cfg(feature = "profile")] + end_timer!(start3); + #[cfg(feature = "profile")] + let start4 = start_timer!(|| "Permutations"); // Permutations let sets = &permutation.sets; if !sets.is_empty() { @@ -463,7 +479,11 @@ impl Evaluator { } }); } + #[cfg(feature = "profile")] + end_timer!(start4); + #[cfg(feature = "profile")] + let start5 = start_timer!(|| "Lookups"); // Lookups for (n, lookup) in lookups.iter().enumerate() { // Polynomials required for this lookup. @@ -534,6 +554,8 @@ impl Evaluator { } }); } + #[cfg(feature = "profile")] + end_timer!(start5); // Shuffle constraints for (n, shuffle) in shuffles.iter().enumerate() { diff --git a/halo2_proofs/src/plonk/prover.rs b/halo2_proofs/src/plonk/prover.rs index bba83bb9b2..bc0b12852f 100644 --- a/halo2_proofs/src/plonk/prover.rs +++ b/halo2_proofs/src/plonk/prover.rs @@ -285,6 +285,8 @@ where fn next_phase(&mut self) { let phase = self.current_phase.to_u8() as usize; + #[cfg(feature = "profile")] + let start1 = start_timer!(|| format!("Phase {phase} inversion and MSM commitment")); if phase == 0 { // Absorb instances into transcript. // Do this here and not earlier in case we want to be able to mutate @@ -370,6 +372,8 @@ where assert!(existing.is_none()); } self.current_phase = self.current_phase.next(); + #[cfg(feature = "profile")] + end_timer!(start1); } } @@ -431,6 +435,11 @@ where // while loop is for compatibility with circuits that do not use the new `next_phase` API to manage phases // If the circuit uses the new API, then the while loop will only execute once while witness.current_phase.to_u8() < num_phases as u8 { + #[cfg(feature = "profile")] + let syn_time = start_timer!(|| format!( + "Synthesize time starting from phase {} (synthesize may cross multiple phases)", + witness.current_phase.to_u8() + )); // Synthesize the circuit to obtain the witness and other information. ConcreteCircuit::FloorPlanner::synthesize( &mut witness, @@ -439,6 +448,8 @@ where meta.constants.clone(), ) .unwrap(); + #[cfg(feature = "profile")] + end_timer!(syn_time); if witness.current_phase.to_u8() < num_phases as u8 { witness.next_phase(); }