Skip to content

Commit bea8c31

Browse files
authored
Improved benchmarking (risc0#1621)
1 parent a7000a9 commit bea8c31

File tree

17 files changed

+403
-235
lines changed

17 files changed

+403
-235
lines changed

.github/workflows/bench_pr.yml

+23-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
os: [Linux, macOS]
30-
feature: [default]
30+
feature: [prove]
3131
device: [cpu]
3232
include:
3333
- os: Linux
@@ -38,16 +38,11 @@ jobs:
3838
device: apple_m2_pro
3939

4040
env:
41-
CI_BENCH_PR: true
4241
FEATURE: ${{ matrix.feature }}
4342
DISABLE_S3: ${{ matrix.device == 'nvidia_rtx_3090_ti' }}
4443

4544
steps:
46-
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
47-
- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
48-
49-
- name: Check out the current PR
50-
uses: actions/checkout@v4
45+
- uses: actions/checkout@v4
5146

5247
- if: matrix.feature == 'cuda'
5348
uses: ./.github/actions/cuda
@@ -59,5 +54,24 @@ jobs:
5954

6055
- run: cargo run --bin cargo-risczero --no-default-features -- risczero install --version $RISC0_TOOLCHAIN_VERSION
6156

62-
- name: Run Benchmarks
63-
run: cargo bench --bench divan -F $FEATURE
57+
- name: Run benchmarks
58+
run: cargo bench --bench fib -F $FEATURE
59+
60+
- name: Download previous benchmark data
61+
uses: actions/cache@v4
62+
with:
63+
path: ./cache
64+
key: fib-${{ runner.os }}-${{ matrix.device }}
65+
66+
- name: Analyze benchmark results
67+
uses: risc0/[email protected]
68+
with:
69+
name: "${{ matrix.os }}-${{ matrix.device }}"
70+
tool: 'customBiggerIsBetter'
71+
output-file-path: target/hotbench/fib/benchmark.json
72+
external-data-json-path: ./cache/benchmark.json
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
74+
alert-threshold: '120%'
75+
comment-on-alert: true
76+
fail-on-alert: true
77+
summary-always: true

.github/workflows/bench_trends.yml

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- 'risc0/**'
99
- '.github/workflows/bench_*'
1010

11+
workflow_dispatch:
12+
1113
# uncomment for only for testing changes to this workflow while in a PR
1214
# pull_request:
1315
# branches: [ main ]
@@ -39,7 +41,7 @@ jobs:
3941
fail-fast: false
4042
matrix:
4143
os: [Linux, macOS]
42-
feature: [default]
44+
feature: [prove]
4345
device: [cpu]
4446
include:
4547
- os: Linux
@@ -51,29 +53,31 @@ jobs:
5153

5254
env:
5355
FEATURE: ${{ matrix.feature }}
56+
DISABLE_S3: ${{ matrix.device == 'nvidia_rtx_3090_ti' }}
5457

5558
steps:
56-
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
57-
- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
5859
- uses: actions/checkout@v4
60+
5961
- if: matrix.feature == 'cuda'
6062
uses: ./.github/actions/cuda
6163
- uses: ./.github/actions/rustup
6264
- uses: ./.github/actions/sccache
6365
with:
6466
key: ${{ matrix.os }}-${{ matrix.feature }}
67+
disable_s3: ${{ env.DISABLE_S3 }}
68+
6569
- run: cargo run --bin cargo-risczero --no-default-features -- risczero install --version $RISC0_TOOLCHAIN_VERSION
66-
- run: cargo bench -F $FEATURE --bench fib -- --output-format=bencher | tee output.txt
70+
71+
- name: Run benchmarks
72+
run: cargo bench -F $FEATURE --bench fib
73+
6774
- name: Store benchmark result
68-
uses: risc0/github-action-benchmark@risc0
75+
uses: risc0/github-action-benchmark@v1.19.3
6976
with:
7077
name: "${{ matrix.os }}-${{ matrix.device }}"
71-
tool: 'cargo'
78+
tool: 'customBiggerIsBetter'
7279
github-token: ${{ secrets.BENCHMARK_TOKEN }}
7380
gh-repository: 'github.com/risc0/ghpages'
74-
gh-repository-dir: '${{ runner.temp }}/benchmark-data-repository'
7581
gh-pages-branch: main
76-
output-file-path: output.txt
77-
comment-always: false
78-
comment-on-alert: false
82+
output-file-path: target/hotbench/fib/benchmark.json
7983
auto-push: true

Cargo.lock

+14-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ members = [
1919
"risc0/zkvm/methods",
2020
"risc0/zkvm/platform",
2121
"risc0/zkvm/receipts",
22+
"tools/hotbench",
2223
"website/doc-test/main",
2324
"xtask",
2425
]
@@ -34,6 +35,7 @@ repository = "https://github.com/risc0/risc0/"
3435
[workspace.dependencies]
3536
bonsai-rest-api-mock = { version = "0.8.0-alpha.1", default-features = false, path = "bonsai/rest-api-mock" }
3637
bonsai-sdk = { version = "0.8.0-alpha.1", default-features = false, path = "bonsai/sdk" }
38+
hotbench = { path = "tools/hotbench" }
3739
risc0-binfmt = { version = "0.22.0-alpha.1", default-features = false, path = "risc0/binfmt" }
3840
risc0-build = { version = "0.22.0-alpha.1", default-features = false, path = "risc0/build" }
3941
risc0-build-kernel = { version = "0.22.0-alpha.1", default-features = false, path = "risc0/build_kernel" }

benchmarks/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bonsai/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/composition/methods/guest/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

risc0/build/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = { workspace = true }
1111
anyhow = "1.0"
1212
# This is a workaround to prevent the guest from pulling in a dependency that requires a newer rustc
1313
cargo-platform = "=0.1.5"
14-
cargo_metadata = "0.17"
14+
cargo_metadata = "0.18"
1515
docker-generate = "0.1"
1616
risc0-binfmt = { workspace = true }
1717
risc0-zkp = { workspace = true, features = ["std"] }

risc0/build/src/docker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ mod test {
239239
build("../../risc0/zkvm/methods/guest/Cargo.toml");
240240
compare_image_id(
241241
"risc0_zkvm_methods_guest/multi_test",
242-
"1219f3a9e9f6a6639705070c151a90d10120f81fdf13d50273080567ea80cb6c",
242+
"254d1845a847dc4a8df7b9663f9418fa41647966109315da4f3dc8622b22dbff",
243243
);
244244
}
245245
}

risc0/build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn build_staticlib(guest_pkg: &str, features: &[&str]) -> String {
358358
let mut child = cmd.stdout(Stdio::piped()).spawn().unwrap();
359359
let reader = std::io::BufReader::new(child.stdout.take().unwrap());
360360
let mut libs = Vec::new();
361-
for message in cargo_metadata::Message::parse_stream(reader) {
361+
for message in Message::parse_stream(reader) {
362362
match message.unwrap() {
363363
Message::CompilerArtifact(artifact) => {
364364
for filename in artifact.filenames {

risc0/zkvm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ typetag = { version = "0.2", optional = true }
8383
clap = { version = "4.4", features = ["derive"] }
8484
criterion = { version = "0.5", features = ["html_reports"] }
8585
divan = "0.1"
86+
hotbench = { workspace = true }
8687
lazy_static = "1.4.0"
8788
rand = "0.8"
8889
tracing-forest = "0.1"

0 commit comments

Comments
 (0)