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

chore: add flamegraph instructions for profiling #318

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Cargo.lock
*.org
.pre-commit-config.yaml
.vscode
**/*flamegraph*

# Test coverage (grcov)
default.profraw
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ where N is the number of threads you want to use (N = 1 for single-thread).

A sample benchmark result is available under [`bench.md`](./bench.md).

## Git Hooks
### Profiling

The pre-commit hooks are installed via the nix shell. To run them on all files use
alxiong marked this conversation as resolved.
Show resolved Hide resolved
You could use `cargo flamegraph` (already installed in the nix-shell) as follows (more [documentations here](https://github.com/flamegraph-rs/flamegraph#examples)):

```
pre-commit run --all-files
``` bash
# --root is necessary for Mac users
cargo flamegraph --root --bench=plonk-benches --features test-srs

# output to a specific file, targeting wasm
cargo flamegraph --root -o path/to/wasm-flamegraph.svg --bench=plonk-benches --no-default-features --features test-srs

# profile a specific test
cargo flamegraph --root --unit-test -p jf-primitives -- pcs::univariate_kzg::tests::end_to_end_test
```
34 changes: 20 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
{
description = "Jellyfish dev env";

nixConfig = {
extra-substituters = [ "https://espresso-systems-private.cachix.org" ];
extra-trusted-public-keys = [
"espresso-systems-private.cachix.org-1:LHYk03zKQCeZ4dvg3NctyCq88e44oBZVug5LpYKjPRI="
];
};

inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils"; # for dedup

Expand All @@ -18,22 +25,20 @@
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";

outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay, pre-commit-hooks, ... }:
outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay
, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [
(import rust-overlay)
];
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.minimal.override { extensions = [ "rustfmt" ]; });
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.minimal.override { extensions = [ "rustfmt" ]; });

stableToolchain = pkgs.rust-bin.stable.latest.minimal.override {
extensions = [ "clippy" "llvm-tools-preview" "rust-src" ];
targets = ["wasm32-unknown-unknown"];
targets = [ "wasm32-unknown-unknown" ];
};
in with pkgs;
{
in with pkgs; {
check = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
Expand Down Expand Up @@ -76,10 +81,12 @@
stableToolchain
nightlyToolchain
cargo-sort
cargo-flamegraph
clang-tools_15
clangStdenv
llvm_15
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
] ++ lib.optionals stdenv.isDarwin
[ darwin.apple_sdk.frameworks.Security ];

shellHook = ''
export RUST_BACKTRACE=full
Expand All @@ -98,9 +105,8 @@
# by default choose u64_backend
export RUSTFLAGS='--cfg curve25519_dalek_backend="u64"'
''
# install pre-commit hooks
+ self.check.${system}.pre-commit-check.shellHook;
# install pre-commit hooks
+ self.check.${system}.pre-commit-check.shellHook;
};
}
);
});
}
10 changes: 7 additions & 3 deletions plonk/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// RAYON_NUM_THREADS=N cargo bench
// where N is the number of threads you want to use (N = 1 for single-thread).

#![cfg(feature = "test-srs")]
use ark_bls12_377::{Bls12_377, Fr as Fr377};
use ark_bls12_381::{Bls12_381, Fr as Fr381};
use ark_bn254::{Bn254, Fr as Fr254};
Expand Down Expand Up @@ -51,7 +52,8 @@ macro_rules! plonk_prove_bench {
let cs = gen_circuit_for_bench::<$bench_field>($num_gates, $bench_plonk_type).unwrap();

let max_degree = $num_gates + 2;
let srs = PlonkKzgSnark::<$bench_curve>::universal_setup(max_degree, rng).unwrap();
let srs =
PlonkKzgSnark::<$bench_curve>::universal_setup_for_testing(max_degree, rng).unwrap();

let (pk, _) = PlonkKzgSnark::<$bench_curve>::preprocess(&srs, &cs).unwrap();

Expand Down Expand Up @@ -90,7 +92,8 @@ macro_rules! plonk_verify_bench {
let cs = gen_circuit_for_bench::<$bench_field>($num_gates, $bench_plonk_type).unwrap();

let max_degree = $num_gates + 2;
let srs = PlonkKzgSnark::<$bench_curve>::universal_setup(max_degree, rng).unwrap();
let srs =
PlonkKzgSnark::<$bench_curve>::universal_setup_for_testing(max_degree, rng).unwrap();

let (pk, vk) = PlonkKzgSnark::<$bench_curve>::preprocess(&srs, &cs).unwrap();

Expand Down Expand Up @@ -132,7 +135,8 @@ macro_rules! plonk_batch_verify_bench {
let cs = gen_circuit_for_bench::<$bench_field>(1024, $bench_plonk_type).unwrap();

let max_degree = 1026;
let srs = PlonkKzgSnark::<$bench_curve>::universal_setup(max_degree, rng).unwrap();
let srs =
PlonkKzgSnark::<$bench_curve>::universal_setup_for_testing(max_degree, rng).unwrap();

let (pk, vk) = PlonkKzgSnark::<$bench_curve>::preprocess(&srs, &cs).unwrap();

Expand Down