Benchmark #68
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Benchmark | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| schedule: | |
| # Run benchmarks every day at 2 AM | |
| - cron: '0 2 * * *' | |
| jobs: | |
| benchmark: | |
| name: Performance Benchmarks | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Need full history for comparison | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run Discover Benchmarks | |
| run: | | |
| go test -bench=. -benchmem -count=5 ./internal/discover/ | tee benchmark_discover.txt | |
| - name: Run Core Benchmarks | |
| run: | | |
| go test -bench=. -benchmem -count=5 ./internal/commands/core/ | tee benchmark_core.txt | |
| - name: Run Test Benchmarks | |
| run: | | |
| go test -bench=. -benchmem -count=5 ./internal/commands/test/ | tee benchmark_test.txt | |
| - name: Process Benchmark Results | |
| run: | | |
| echo "## Benchmark Results" > benchmark_report.md | |
| echo "" >> benchmark_report.md | |
| echo "### Discover Package" >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| cat benchmark_discover.txt >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| echo "" >> benchmark_report.md | |
| echo "### Core Package" >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| cat benchmark_core.txt >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| echo "" >> benchmark_report.md | |
| echo "### Test Package" >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| cat benchmark_test.txt >> benchmark_report.md | |
| echo "\`\`\`" >> benchmark_report.md | |
| - name: Upload Benchmark Results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: benchmark-results | |
| path: | | |
| benchmark_*.txt | |
| benchmark_report.md | |
| - name: Compare with Previous Benchmark | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| # Install benchstat for comparison | |
| go install golang.org/x/perf/cmd/benchstat@latest | |
| # Try to get baseline from main branch | |
| git stash | |
| git checkout main | |
| go test -bench=. -count=5 ./internal/discover/ > baseline_discover.txt || true | |
| go test -bench=. -count=5 ./internal/commands/core/ > baseline_core.txt || true | |
| git checkout - | |
| git stash pop | |
| # Compare results | |
| echo "## Benchmark Comparison (PR vs Main)" > benchmark_comparison.md | |
| echo "" >> benchmark_comparison.md | |
| if [ -f baseline_discover.txt ]; then | |
| echo "### Discover Package" >> benchmark_comparison.md | |
| echo "\`\`\`" >> benchmark_comparison.md | |
| benchstat baseline_discover.txt benchmark_discover.txt >> benchmark_comparison.md 2>/dev/null || echo "No comparison available" >> benchmark_comparison.md | |
| echo "\`\`\`" >> benchmark_comparison.md | |
| echo "" >> benchmark_comparison.md | |
| fi | |
| if [ -f baseline_core.txt ]; then | |
| echo "### Core Package" >> benchmark_comparison.md | |
| echo "\`\`\`" >> benchmark_comparison.md | |
| benchstat baseline_core.txt benchmark_core.txt >> benchmark_comparison.md 2>/dev/null || echo "No comparison available" >> benchmark_comparison.md | |
| echo "\`\`\`" >> benchmark_comparison.md | |
| fi | |
| - name: Comment PR with Benchmark Results | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const benchmarkReport = fs.readFileSync('benchmark_report.md', 'utf8'); | |
| let comparisonReport = ''; | |
| try { | |
| comparisonReport = fs.readFileSync('benchmark_comparison.md', 'utf8'); | |
| } catch (e) { | |
| comparisonReport = 'No comparison available'; | |
| } | |
| const body = `## 📊 Benchmark Results | |
| ${comparisonReport} | |
| <details> | |
| <summary>View Full Results</summary> | |
| ${benchmarkReport} | |
| </details> | |
| `; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| benchmark-regression: | |
| name: Benchmark Regression Check | |
| runs-on: ubuntu-latest | |
| needs: benchmark | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| - name: Download Benchmark Results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: benchmark-results | |
| - name: Check for Performance Regression | |
| run: | | |
| # Simple check: fail if any benchmark is >20% slower | |
| # This is a basic check; in production, use benchstat | |
| echo "Checking for performance regressions..." | |
| # Parse benchmark results and check for regressions | |
| REGRESSION_FOUND=false | |
| # Check discover benchmarks | |
| if grep -q "ns/op" benchmark_discover.txt; then | |
| # Extract benchmark times and compare | |
| # This is simplified; real implementation would compare with baseline | |
| echo "✓ Discover benchmarks completed" | |
| fi | |
| if [ "$REGRESSION_FOUND" = true ]; then | |
| echo "❌ Performance regression detected!" | |
| exit 1 | |
| else | |
| echo "✅ No significant performance regression detected" | |
| fi | |
| cache-performance: | |
| name: Cache Performance Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| - name: Run Cache Performance Test | |
| run: | | |
| go test -v -run TestRewriteCommandCaching ./internal/discover/ | |
| - name: Verify Cache Hit Rate | |
| run: | | |
| # The test already verifies this, but we can add additional checks | |
| echo "Cache performance tests completed" |