From 12748c0dfa1a8f456980a93eff3f0400932c3365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Str=C3=B6m?= Date: Fri, 20 Jun 2025 13:42:56 +0000 Subject: [PATCH] Test codspeed in op-rbuilder --- .github/workflows/codspeed.yaml | 76 ++++++++++++++++++ Cargo.lock | 98 ++++++++++++++++++++++++ crates/op-rbuilder/Cargo.toml | 5 ++ crates/op-rbuilder/benches/test_bench.rs | 14 ++++ 4 files changed, 193 insertions(+) create mode 100644 .github/workflows/codspeed.yaml create mode 100644 crates/op-rbuilder/benches/test_bench.rs diff --git a/.github/workflows/codspeed.yaml b/.github/workflows/codspeed.yaml new file mode 100644 index 000000000..872224c8e --- /dev/null +++ b/.github/workflows/codspeed.yaml @@ -0,0 +1,76 @@ +name: CodSpeed + +on: + push: + branches: + - "main" + - "codspeed" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + codspeed: + name: Run benchmarks + runs-on: warp-ubuntu-latest-x64-32x + env: + # Set features for the Makefile + FEATURES: ${{ matrix.features }} + RUSTFLAGS: "-Awarnings" + strategy: + matrix: + toolchain: + - stable + features: + - "" + steps: + - uses: actions/checkout@v4 + + - name: Setup rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.toolchain }} + + - name: Download builder playground + uses: flashbots/flashbots-toolchain@v0.1 + with: + builder-playground: v0.1.3 + + # https://github.com/swatinem/rust-cache + - name: Run Swatinem/rust-cache@v2 + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + # https://github.com/Mozilla-Actions/sccache-action + - name: Run sccache-action + uses: mozilla-actions/sccache-action@v0.0.9 + + - name: Set sccache env vars + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + + - name: Build the rbuilder + run: cargo build --features="${{ matrix.features }}" + + - name: Run the playground + run: builder-playground & + + - name: Install codspeed + run: cargo install cargo-codspeed + + # - name: Set Swap Space + # uses: pierotofy/set-swap-space@master + # with: + # swap-size-gb: 64 + + - name: Build the benchmark target(s) + run: cargo codspeed build + + - name: Run the benchmarks + uses: CodSpeedHQ/action@v3 + with: + run: cargo codspeed run + token: ${{ secrets.CODSPEED_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index d9dc6c20d..f4e5865f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2135,6 +2135,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim", + "terminal_size", ] [[package]] @@ -2164,12 +2165,75 @@ dependencies = [ "cc", ] +[[package]] +name = "codspeed" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f4cce9c27c49c4f101fffeebb1826f41a9df2e7498b7cd4d95c0658b796c6c" +dependencies = [ + "colored", + "libc", + "serde", + "serde_json", + "uuid", +] + +[[package]] +name = "codspeed-divan-compat" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8620a09dfaf37b3c45f982c4b65bd8f9b0203944da3ffa705c0fcae6b84655ff" +dependencies = [ + "codspeed", + "codspeed-divan-compat-macros", + "codspeed-divan-compat-walltime", +] + +[[package]] +name = "codspeed-divan-compat-macros" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30fe872bc4214626b35d3a1706a905d0243503bb6ba3bb7be2fc59083d5d680c" +dependencies = [ + "divan-macros", + "itertools 0.14.0", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "codspeed-divan-compat-walltime" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "104caa97b36d4092d89e24e4b103b40ede1edab03c0372d19e14a33f9393132b" +dependencies = [ + "cfg-if", + "clap", + "codspeed", + "condtype", + "divan-macros", + "libc", + "regex-lite", +] + [[package]] name = "colorchoice" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + [[package]] name = "combine" version = "4.6.7" @@ -2223,6 +2287,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.11" @@ -2827,6 +2897,17 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "divan-macros" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc51d98e636f5e3b0759a39257458b22619cac7e96d932da6eeb052891bb67c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "doctest-file" version = "1.0.0" @@ -5683,6 +5764,7 @@ dependencies = [ "chrono", "clap", "clap_builder", + "codspeed-divan-compat", "ctor", "dashmap 6.1.0", "derive_more", @@ -6793,6 +6875,12 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "regex-syntax" version = "0.6.29" @@ -11040,6 +11128,16 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "terminal_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +dependencies = [ + "rustix 1.0.7", + "windows-sys 0.59.0", +] + [[package]] name = "thin-vec" version = "0.2.14" diff --git a/crates/op-rbuilder/Cargo.toml b/crates/op-rbuilder/Cargo.toml index 5e8287065..1c83ea06d 100644 --- a/crates/op-rbuilder/Cargo.toml +++ b/crates/op-rbuilder/Cargo.toml @@ -142,6 +142,7 @@ reth-ipc = { workspace = true } reth-node-builder = { workspace = true, features = ["test-utils"] } bollard = "0.19" ctor = "0.4.2" +divan = { version = "2.10.1", package = "codspeed-divan-compat" } [features] default = ["jemalloc"] @@ -188,3 +189,7 @@ path = "src/bin/op-rbuilder/main.rs" [[bin]] name = "tester" required-features = ["testing"] + +[[bench]] +harness = false +name = "test_bench" \ No newline at end of file diff --git a/crates/op-rbuilder/benches/test_bench.rs b/crates/op-rbuilder/benches/test_bench.rs new file mode 100644 index 000000000..992933250 --- /dev/null +++ b/crates/op-rbuilder/benches/test_bench.rs @@ -0,0 +1,14 @@ +fn main() { + // Run registered benchmarks. + divan::main(); +} + +// Register a `fibonacci` function and benchmark it over multiple cases. +#[divan::bench(args = [1, 2, 4, 8, 16, 32])] +fn test_bench(n: u64) -> u64 { + if n <= 1 { + 1 + } else { + test_bench(n - 2) + test_bench(n - 1) + } +}