Skip to content

Commit a4f86b0

Browse files
authored
feat: set up codspeed (paradigmxyz#13372)
1 parent 3966130 commit a4f86b0

File tree

34 files changed

+316
-396
lines changed

34 files changed

+316
-396
lines changed

.github/scripts/codspeed-build.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
# TODO: Benchmarks run WAY too slow due to excessive amount of iterations.
5+
6+
cmd=(cargo codspeed build --profile profiling)
7+
excludes=(
8+
# Unnecessary
9+
--exclude reth-libmdbx
10+
# Build is too slow
11+
--exclude reth-network
12+
# Built separately
13+
--exclude reth-transaction-pool
14+
# TODO: some benchmarks panic: https://github.com/paradigmxyz/reth/actions/runs/12307046814/job/34349955788
15+
--exclude reth-db
16+
--exclude reth-trie-parallel
17+
--exclude reth-engine-tree
18+
)
19+
20+
"${cmd[@]}" --features test-utils --workspace "${excludes[@]}"
21+
22+
# TODO: Slow benchmarks due to too many iterations
23+
## "${cmd[@]}" -p reth-transaction-pool --features test-utils,arbitrary

.github/workflows/bench.yml

+14-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Runs benchmarks on serialization/deserialization of storage values and keys.
1+
# Runs benchmarks.
22

33
on:
44
pull_request:
@@ -9,55 +9,33 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111
BASELINE: base
12-
IAI_CALLGRIND_RUNNER: iai-callgrind-runner
1312

1413
concurrency:
1514
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1615
cancel-in-progress: true
1716

1817
name: bench
1918
jobs:
20-
iai:
19+
codspeed:
2120
runs-on:
2221
group: Reth
23-
# Only run benchmarks in merge groups and on main
24-
if: github.event_name != 'pull_request'
2522
steps:
2623
- uses: actions/checkout@v4
27-
- name: Install Valgrind
28-
run: sudo apt update && sudo apt install valgrind
24+
with:
25+
submodules: true
26+
- uses: rui314/setup-mold@v1
2927
- uses: dtolnay/rust-toolchain@stable
3028
- uses: Swatinem/rust-cache@v2
3129
with:
3230
cache-on-failure: true
33-
- name: Install cargo-binstall
34-
uses: taiki-e/install-action@cargo-binstall
35-
- name: Install iai-callgrind-runner
36-
run: |
37-
echo "::group::Install"
38-
version=$(cargo metadata --format-version=1 |\
39-
jq '.packages[] | select(.name == "iai-callgrind").version' |\
40-
tr -d '"'
41-
)
42-
cargo binstall iai-callgrind-runner --version $version --no-confirm --no-symlinks --force
43-
echo "::endgroup::"
44-
echo "::group::Verification"
45-
which iai-callgrind-runner
46-
echo "::endgroup::"
47-
- name: Checkout base
48-
uses: actions/checkout@v4
31+
- name: Install cargo-codspeed
32+
uses: taiki-e/install-action@v2
4933
with:
50-
ref: ${{ github.base_ref || 'main' }}
51-
# On `main` branch, generates test vectors and serializes them to disk using `serde-json`.
52-
- name: Generate test vectors
53-
run: cargo run --bin reth --features dev -- test-vectors tables
54-
# Runs iai and stores `main` baseline report for comparison later on $BASELINE.
55-
- name: Save baseline
56-
run: cargo bench -p reth-db --bench iai --profile profiling --features test-utils -- --save-baseline=$BASELINE
57-
- name: Checkout PR
58-
uses: actions/checkout@v4
34+
tool: cargo-codspeed
35+
- name: Build the benchmark target(s)
36+
run: ./.github/scripts/codspeed-build.sh
37+
- name: Run the benchmarks
38+
uses: CodSpeedHQ/action@v3
5939
with:
60-
clean: false
61-
# Runs iai on incoming merge using previously generated test-vectors and compares the report against `main` report.
62-
- name: Compare PR benchmarks
63-
run: cargo bench -p reth-db --bench iai --profile profiling --features test-utils -- --baseline=$BASELINE
40+
run: cargo codspeed run --workspace
41+
token: ${{ secrets.CODSPEED_TOKEN }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ target/
1919
testdata/micro/db
2020

2121
# Generated data for stage benchmarks
22-
crates/stages/testdata
22+
crates/stages/stages/testdata
2323

2424
# Prometheus data dir
2525
data/

Cargo.lock

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

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ toml = "0.8"
601601
# misc-testing
602602
arbitrary = "1.3"
603603
assert_matches = "1.5.0"
604-
criterion = "0.5"
605-
iai-callgrind = "0.14"
604+
criterion = { package = "codspeed-criterion-compat", version = "2.7" }
606605
pprof = "0.14"
607606
proptest = "1.4"
608607
proptest-derive = "0.5"

crates/blockchain-tree/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ test-utils = [
7777
"reth-db-api/test-utils",
7878
"reth-provider/test-utils",
7979
"reth-trie-db/test-utils",
80-
"reth-trie/test-utils"
80+
"reth-trie/test-utils",
81+
"reth-trie-parallel/test-utils"
8182
]
8283
optimism = [
8384
"reth-primitives/optimism",

crates/engine/tree/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ test-utils = [
120120
"reth-static-file",
121121
"reth-tracing",
122122
"reth-trie/test-utils",
123-
"reth-trie-db/test-utils",
123+
"reth-trie-sparse/test-utils",
124124
"reth-prune-types?/test-utils",
125+
"reth-trie-db/test-utils",
126+
"reth-trie-parallel/test-utils",
125127
]

crates/engine/tree/benches/channel_perf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use revm_primitives::{
77
Account, AccountInfo, AccountStatus, Address, EvmState, EvmStorage, EvmStorageSlot, HashMap,
88
B256, U256,
99
};
10-
use std::thread;
10+
use std::{hint::black_box, thread};
1111

1212
/// Creates a mock state with the specified number of accounts for benchmarking
1313
fn create_bench_state(num_accounts: usize) -> EvmState {
@@ -47,7 +47,7 @@ impl StdStateRootTask {
4747

4848
fn run(self) {
4949
while let Ok(state) = self.rx.recv() {
50-
criterion::black_box(state);
50+
black_box(state);
5151
}
5252
}
5353
}
@@ -64,7 +64,7 @@ impl CrossbeamStateRootTask {
6464

6565
fn run(self) {
6666
while let Ok(state) = self.rx.recv() {
67-
criterion::black_box(state);
67+
black_box(state);
6868
}
6969
}
7070
}

crates/engine/tree/benches/state_root_task.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
#![allow(missing_docs)]
55

6-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
6+
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
77
use reth_engine_tree::tree::root::{StateRootConfig, StateRootTask};
88
use reth_evm::system_calls::OnStateHook;
99
use reth_primitives::{Account as RethAccount, StorageEntry};
@@ -22,6 +22,7 @@ use revm_primitives::{
2222
Account as RevmAccount, AccountInfo, AccountStatus, Address, EvmState, EvmStorageSlot, HashMap,
2323
B256, KECCAK_EMPTY, U256,
2424
};
25+
use std::hint::black_box;
2526

2627
#[derive(Debug, Clone)]
2728
struct BenchParams {

crates/net/ecies/src/algorithm.rs

-1
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,5 @@ mod tests {
975975
&mut dest,
976976
);
977977
}
978-
std::hint::black_box(());
979978
}
980979
}

crates/primitives/benches/validate_blob_tx.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ fn validate_blob_tx(
6969

7070
// for now we just use the default SubPoolLimit
7171
group.bench_function(group_id, |b| {
72+
let kzg_settings = kzg_settings.get();
7273
b.iter_with_setup(setup, |(tx, blob_sidecar)| {
73-
if let Err(err) =
74-
std::hint::black_box(tx.validate_blob(&blob_sidecar, kzg_settings.get()))
75-
{
76-
println!("Validation failed: {err:?}");
77-
}
74+
let r = tx.validate_blob(&blob_sidecar, kzg_settings);
75+
(r, tx, blob_sidecar)
7876
});
7977
});
8078
}

0 commit comments

Comments
 (0)