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

feat: Add basic benchmarking #2213

Merged
merged 23 commits into from
Aug 11, 2023
8 changes: 8 additions & 0 deletions .github/scripts/compare_iai.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script should be run on the main branch, after running the iai benchmarks on the target branch.

# If the main branch has a better iai performance, exits in error. It ignores L2 differences, since they seem hard to stabilize across runs.
cargo bench --bench iai --manifest-path pr/Cargo.toml | tee /dev/tty | awk '/((L1)|(Ins)|(RAM)|(Est))+.*\(\+[1-9]+[0-9]*\..*%\)/{f=1} END{exit f}'

# copied from https://github.com/paradigmxyz/reth/blob/main/.github/scripts/compare_iai.sh
132 changes: 132 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Adapted from https://github.com/paradigmxyz/reth/blob/main/.github/workflows/bench.yml
name: Bench

on:
pull_request:
merge_group:

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

jobs:
benchmark:
name: Bench selected tests
runs-on: ubuntu-latest
# Only run benchmarks in merge groups
if: github.event_name != 'pull_request'
steps:
- name: Checkout Noir repo
uses: actions/checkout@v3

- name: Collect locked barretenberg rev
run: |
echo "BB_REV=$(jq -r .nodes.barretenberg.locked.rev ./flake.lock)" >> $GITHUB_ENV
echo "BB_REV is ${{ env.BB_REV }}"

- name: Checkout barretenberg
uses: actions/checkout@v3
with:
repository: AztecProtocol/barretenberg
path: barretenberg
ref: ${{ env.BB_REV }}

- name: Setup Linux environment
run: |
sudo apt update
sudo apt install libomp-dev cmake ninja-build
echo "PRESET=default" >> $GITHUB_ENV

- name: Build and install barretenberg
working-directory: barretenberg/cpp
run: |
cmake --preset ${{ env.PRESET }} -DTESTING=OFF -DBENCHMARKS=OFF -DCMAKE_BUILD_TYPE=RelWithAssert -DDISABLE_ASM=ON -DDISABLE_ADX=ON
cmake --build --preset ${{ env.PRESET }}
sudo cmake --install build

- name: Checkout master sources
uses: actions/checkout@v3
with:
ref: master
path: master

- name: Checkout PR sources
uses: actions/checkout@v3
with:
clean: false
path: pr

- name: Setup toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.66.0

- name: Install Valgrind
run: |
sudo apt install valgrind

- name: Set master baseline
run: cargo bench --bench iai --manifest-path master/Cargo.toml

- name: Compare PR benchmark
shell: 'script -q -e -c "bash {0}"' # required to workaround /dev/tty not being available
run: |
./pr/.github/scripts/compare_iai.sh

# Checks that benchmarks not run in CI compile
bench-check:
name: check
runs-on: ubuntu-latest
steps:
- name: Checkout Noir repo
uses: actions/checkout@v3

- name: Collect locked barretenberg rev
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "BB_REV=$(jq -r .nodes.barretenberg.locked.rev ./flake.lock)" >> $GITHUB_ENV
echo "BB_REV is ${{ env.BB_REV }}"

- name: Checkout barretenberg
uses: actions/checkout@v3
with:
repository: AztecProtocol/barretenberg
path: barretenberg
ref: ${{ env.BB_REV }}

- name: Setup Linux environment
run: |
sudo apt update
sudo apt install libomp-dev cmake ninja-build
echo "PRESET=default" >> $GITHUB_ENV

- name: Build and install barretenberg
working-directory: barretenberg/cpp
run: |
cmake --preset ${{ env.PRESET }} -DTESTING=OFF -DBENCHMARKS=OFF -DCMAKE_BUILD_TYPE=RelWithAssert -DDISABLE_ASM=ON -DDISABLE_ADX=ON
cmake --build --preset ${{ env.PRESET }}
sudo cmake --install build

- name: Checkout Noir repo
uses: actions/checkout@v3

- name: Setup toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.66.0

- name: Check if benchmarks build
run: cargo check --workspace --benches

bench-success:
if: always()
name: bench success
needs: bench-check
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
Loading