From bf1aac3e28e0e7eac0143ad585bf58cf8e55ca98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Fri, 16 Jun 2023 11:50:48 -0400 Subject: [PATCH 1/2] feat: Integrate flamegraph profiling in benchmarks - Introduce "flamegraph" feature flag for optional profiling integration - Add benchmark profiling support in `compressed_snark` and `recursive_snark` groups - Update Cargo.toml with `pprof` and `cfg-if` dependencies --- Cargo.toml | 3 +++ benches/compressed-snark.rs | 22 ++++++++++++++++++---- benches/recursive-snark.rs | 22 ++++++++++++++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7a2c53f0..ed8eb282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,8 @@ pasta-msm = { version = "0.1.4" } criterion = { version = "0.4", features = ["html_reports"] } rand = "0.8.4" hex = "0.4.3" +pprof = { version = "0.11" } +cfg-if = "1.0.0" [[bench]] name = "recursive-snark" @@ -59,3 +61,4 @@ default = [] portable = ["pasta-msm/portable"] cuda = ["neptune/cuda", "neptune/pasta", "neptune/arity24"] opencl = ["neptune/opencl", "neptune/pasta", "neptune/arity24"] +flamegraph = ["pprof/flamegraph", "pprof/criterion"] diff --git a/benches/compressed-snark.rs b/benches/compressed-snark.rs index 4a06b6d4..db64f9a6 100644 --- a/benches/compressed-snark.rs +++ b/benches/compressed-snark.rs @@ -22,10 +22,24 @@ type S2 = nova_snark::spartan::RelaxedR1CSSNARK; type C1 = NonTrivialTestCircuit<::Scalar>; type C2 = TrivialTestCircuit<::Scalar>; -criterion_group! { -name = compressed_snark; -config = Criterion::default().warm_up_time(Duration::from_millis(3000)); -targets = bench_compressed_snark +// To run these benchmarks, first download `criterion` with `cargo install cargo install cargo-criterion`. +// Then `cargo criterion --bench compressed-snark`. The results are located in `target/criterion/data/`. +// For flamegraphs, run `cargo criterion --bench compressed-snark --features flamegraph -- --profile-time `. +// The results are located in `target/criterion/profile/`. +cfg_if::cfg_if! { + if #[cfg(feature = "flamegraph")] { + criterion_group! { + name = compressed_snark; + config = Criterion::default().warm_up_time(Duration::from_millis(3000)).with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); + targets = bench_compressed_snark + } + } else { + criterion_group! { + name = compressed_snark; + config = Criterion::default().warm_up_time(Duration::from_millis(3000)); + targets = bench_compressed_snark + } + } } criterion_main!(compressed_snark); diff --git a/benches/recursive-snark.rs b/benches/recursive-snark.rs index aec865da..fe20513e 100644 --- a/benches/recursive-snark.rs +++ b/benches/recursive-snark.rs @@ -18,10 +18,24 @@ type G2 = pasta_curves::vesta::Point; type C1 = NonTrivialTestCircuit<::Scalar>; type C2 = TrivialTestCircuit<::Scalar>; -criterion_group! { -name = recursive_snark; -config = Criterion::default().warm_up_time(Duration::from_millis(3000)); -targets = bench_recursive_snark +// To run these benchmarks, first download `criterion` with `cargo install cargo install cargo-criterion`. +// Then `cargo criterion --bench recursive-snark`. The results are located in `target/criterion/data/`. +// For flamegraphs, run `cargo criterion --bench recursive-snark --features flamegraph -- --profile-time `. +// The results are located in `target/criterion/profile/`. +cfg_if::cfg_if! { + if #[cfg(feature = "flamegraph")] { + criterion_group! { + name = recursive_snark; + config = Criterion::default().warm_up_time(Duration::from_millis(3000)).with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); + targets = bench_recursive_snark + } + } else { + criterion_group! { + name = recursive_snark; + config = Criterion::default().warm_up_time(Duration::from_millis(3000)); + targets = bench_recursive_snark + } + } } criterion_main!(recursive_snark); From a1b6b4c2fa258d9c2e3680168249f30341c8c9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Fri, 16 Jun 2023 12:02:08 -0400 Subject: [PATCH 2/2] ci: Build benches to make sure they don't bit-rot - Integrate bench build step into GitHub Actions workflow --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7ad2b8fd..ba4ed36e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,6 +25,8 @@ jobs: run: cargo build --target wasm32-unknown-unknown - name: Build examples run: cargo build --examples --verbose + - name: Build benches + run: cargo build --benches --verbose - name: Run tests run: cargo +stable test --release --verbose - name: Check Rustfmt Code Style