name: Performance Regression Detection on: pull_request: branches: [ main ] push: branches: [ main ] # Allow manual triggering workflow_dispatch: env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 jobs: benchmark: name: Run Performance Benchmarks runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Need full history for comparison - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - name: Cache cargo registry uses: actions/cache@v4 with: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-registry- - name: Cache cargo index uses: actions/cache@v4 with: path: ~/.cargo/git key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-index- - name: Cache target directory uses: actions/cache@v4 with: path: target key: ${{ runner.os }}-target-bench-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-target-bench- - name: Install criterion dependencies run: | sudo apt-get update sudo apt-get install -y gnuplot - name: Run benchmarks run: | cargo bench --workspace --all-features -- --save-baseline current - name: Download previous baseline if: github.event_name == 'pull_request' continue-on-error: true uses: actions/download-artifact@v4 with: name: benchmark-baseline path: target/criterion - name: Compare with baseline if: github.event_name == 'pull_request' run: | cargo bench --workspace --all-features -- --baseline main --load-baseline current - name: Upload benchmark results if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: actions/upload-artifact@v4 with: name: benchmark-baseline path: target/criterion retention-days: 90 - name: Generate performance report run: | echo "# Performance Benchmark Results" > benchmark_report.md echo "" >> benchmark_report.md echo "## Summary" >> benchmark_report.md echo "" >> benchmark_report.md # Trading Latency echo "### Trading Latency Benchmarks" >> benchmark_report.md echo "- Order creation: See criterion HTML reports" >> benchmark_report.md echo "- Market event processing: See criterion HTML reports" >> benchmark_report.md echo "- Position calculations: See criterion HTML reports" >> benchmark_report.md echo "" >> benchmark_report.md # Database Performance echo "### Database Performance Benchmarks" >> benchmark_report.md echo "- Connection acquisition: See criterion HTML reports" >> benchmark_report.md echo "- Query execution: See criterion HTML reports" >> benchmark_report.md echo "- Pool saturation: See criterion HTML reports" >> benchmark_report.md echo "" >> benchmark_report.md # Streaming Throughput echo "### Streaming Throughput Benchmarks" >> benchmark_report.md echo "- Message throughput: See criterion HTML reports" >> benchmark_report.md echo "- Stream latency: See criterion HTML reports" >> benchmark_report.md echo "- Backpressure handling: See criterion HTML reports" >> benchmark_report.md echo "" >> benchmark_report.md # Metrics Overhead echo "### Metrics Overhead Benchmarks" >> benchmark_report.md echo "- Observation overhead: See criterion HTML reports" >> benchmark_report.md echo "- Registry lookup: See criterion HTML reports" >> benchmark_report.md echo "- Label cardinality: See criterion HTML reports" >> benchmark_report.md echo "" >> benchmark_report.md # End-to-End echo "### End-to-End Pipeline Benchmarks" >> benchmark_report.md echo "- Full pipeline latency: See criterion HTML reports" >> benchmark_report.md echo "- Pipeline under load: See criterion HTML reports" >> benchmark_report.md echo "- Risk validation overhead: See criterion HTML reports" >> benchmark_report.md echo "" >> benchmark_report.md echo "## Performance Targets" >> benchmark_report.md echo "" >> benchmark_report.md echo "| Component | Target | Status |" >> benchmark_report.md echo "|-----------|--------|--------|" >> benchmark_report.md echo "| Order Processing | <50μs p99 | ⏳ See reports |" >> benchmark_report.md echo "| Risk Validation | <5μs p99 | ⏳ See reports |" >> benchmark_report.md echo "| Market Data Processing | <10μs p99 | ⏳ See reports |" >> benchmark_report.md echo "| Event Queue | <1μs p99 | ⏳ See reports |" >> benchmark_report.md echo "| DB Connection | <5ms p99 | ⏳ See reports |" >> benchmark_report.md echo "| gRPC Streaming | >10K msg/sec | ⏳ See reports |" >> benchmark_report.md echo "| Metrics Collection | <5μs | ⏳ See reports |" >> benchmark_report.md echo "| End-to-End Pipeline | <200μs p99 | ⏳ See reports |" >> benchmark_report.md echo "" >> benchmark_report.md echo "Detailed HTML reports available in CI artifacts under \`target/criterion\`" >> benchmark_report.md - name: Upload performance report uses: actions/upload-artifact@v4 with: name: performance-report path: benchmark_report.md retention-days: 30 - name: Comment PR with results if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | const fs = require('fs'); const report = fs.readFileSync('benchmark_report.md', 'utf8'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: report }); regression-check: name: Check for Performance Regressions runs-on: ubuntu-latest needs: benchmark if: github.event_name == 'pull_request' steps: - name: Checkout code uses: actions/checkout@v4 - name: Download benchmark results uses: actions/download-artifact@v4 with: name: benchmark-baseline path: current-results - name: Analyze regressions run: | echo "Checking for performance regressions..." echo "⚠️ Manual review of criterion HTML reports required" echo "📊 Check for >10% performance degradation in critical paths" echo "" echo "Critical paths to review:" echo "- Order processing latency" echo "- Risk validation overhead" echo "- Event queue operations" echo "- Database connection acquisition" echo "- gRPC message throughput" echo "" echo "If regressions found, investigate before merging!"