name: Benchmarks
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
full_benchmark:
description: 'Run full benchmarks including 1M node test'
required: false
default: 'false'
type: boolean
env:
CARGO_TERM_COLOR: always
jobs:
benchmark:
name: Quick Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
- name: Download previous baseline (if exists)
uses: actions/cache@v4
with:
path: target/criterion
key: benchmark-baseline-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
benchmark-baseline-${{ runner.os }}-
- name: Run quick benchmarks
run: |
cargo bench --bench graph_benchmarks -- \
"basic_benches" \
"memory_benches" \
--save-baseline current 2>&1 | tee benchmark_results.txt
- name: Compare with baseline
run: |
echo "=== Performance Comparison ===" >> benchmark_results.txt
if [ -d "target/criterion" ]; then
echo "Baseline found, comparing..." >> benchmark_results.txt
# Check for significant regressions (>10% slower)
grep -E "(time:|thrpt:)" benchmark_results.txt | head -20 >> benchmark_results.txt
else
echo "No baseline found, establishing new baseline" >> benchmark_results.txt
fi
- name: Save baseline for future comparisons
uses: actions/cache/save@v4
if: github.ref == 'refs/heads/main'
with:
path: target/criterion
key: benchmark-baseline-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark_results.txt
retention-days: 7
- name: Check for regressions
run: |
if grep -q "regressed" benchmark_results.txt; then
echo "⚠️ Performance regression detected!"
grep "regressed" benchmark_results.txt
# Don't fail for now, just warn
# exit 1
fi
full-benchmark:
name: Full Benchmarks
runs-on: ubuntu-latest
if: github.event.inputs.full_benchmark == 'true' || github.event_name == 'schedule'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-bench-full-${{ hashFiles('**/Cargo.lock') }}
- name: Install critcmp for comparison
run: cargo install critcmp
- name: Run full benchmarks
run: |
cargo bench --bench graph_benchmarks -- --save-baseline current 2>&1 | tee benchmark_results.txt
- name: Upload full benchmark results
uses: actions/upload-artifact@v4
with:
name: full-benchmark-results
path: benchmark_results.txt
retention-days: 30
memory_profile:
name: Memory Profile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-memory-${{ hashFiles('**/Cargo.lock') }}
- name: Run memory tests
run: |
cargo test --release memory_usage -- --nocapture 2>&1 | tee memory_output.txt || true
echo "Memory test completed"
- name: Upload memory results
uses: actions/upload-artifact@v4
with:
name: memory-results
path: memory_output.txt
retention-days: 7