|
| 1 | +name: Scrolling Performance Gate |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + paths-ignore: |
| 7 | + - '**.md' |
| 8 | + pull_request: |
| 9 | + branches: [ main, develop ] |
| 10 | + paths-ignore: |
| 11 | + - '**.md' |
| 12 | + |
| 13 | +# Only run on Linux to keep results comparable across runs. |
| 14 | +# Windows/macOS times vary too much to use as a performance baseline. |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + perf-smoke-tests: |
| 20 | + name: Performance Smoke Tests (Linux) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 20 |
| 23 | + env: |
| 24 | + DisableRealDriverIO: "1" |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + fetch-depth: 0 # GitVersion needs full history |
| 31 | + |
| 32 | + - name: Setup .NET |
| 33 | + uses: actions/setup-dotnet@v5 |
| 34 | + with: |
| 35 | + dotnet-version: 10.x |
| 36 | + dotnet-quality: 'ga' |
| 37 | + |
| 38 | + - name: Restore dependencies |
| 39 | + run: dotnet restore |
| 40 | + |
| 41 | + - name: Build (Release) |
| 42 | + run: dotnet build --configuration Release --no-restore -property:NoWarn=0618%3B0612 |
| 43 | + |
| 44 | + - name: Build Tests (Debug — smoke tests run in Debug to match CI unit tests) |
| 45 | + run: dotnet build Tests/PerformanceTests --no-restore -property:NoWarn=0618%3B0612 |
| 46 | + |
| 47 | + - name: Run performance smoke tests (Layer 1 gate) |
| 48 | + id: smoke_tests |
| 49 | + run: | |
| 50 | + dotnet test \ |
| 51 | + --project Tests/PerformanceTests \ |
| 52 | + --no-build \ |
| 53 | + --verbosity normal |
| 54 | +
|
| 55 | + - name: Upload smoke test logs |
| 56 | + if: always() |
| 57 | + uses: actions/upload-artifact@v7 |
| 58 | + with: |
| 59 | + name: perf-smoke-test-logs |
| 60 | + path: | |
| 61 | + TestResults/ |
| 62 | + if-no-files-found: ignore |
| 63 | + retention-days: 7 |
| 64 | + |
| 65 | + perf-benchmarks: |
| 66 | + name: Scrolling Benchmarks (Linux, ShortRun) |
| 67 | + runs-on: ubuntu-latest |
| 68 | + # Only run on pushes to develop/main, not on every PR (slow and not blocking). |
| 69 | + if: github.event_name == 'push' |
| 70 | + timeout-minutes: 30 |
| 71 | + env: |
| 72 | + DisableRealDriverIO: "1" |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Checkout code |
| 76 | + uses: actions/checkout@v6 |
| 77 | + with: |
| 78 | + fetch-depth: 0 |
| 79 | + |
| 80 | + - name: Setup .NET |
| 81 | + uses: actions/setup-dotnet@v5 |
| 82 | + with: |
| 83 | + dotnet-version: 10.x |
| 84 | + dotnet-quality: 'ga' |
| 85 | + |
| 86 | + - name: Restore dependencies |
| 87 | + run: dotnet restore |
| 88 | + |
| 89 | + - name: Build Release |
| 90 | + run: dotnet build --configuration Release --no-restore -property:NoWarn=0618%3B0612 |
| 91 | + |
| 92 | + - name: Run scrolling benchmarks (ShortRun ≈ 30–60 s) |
| 93 | + id: run_benchmarks |
| 94 | + run: | |
| 95 | + dotnet run \ |
| 96 | + --project Tests/Benchmarks \ |
| 97 | + --configuration Release \ |
| 98 | + --no-build \ |
| 99 | + -- \ |
| 100 | + --filter '*Scroll*' \ |
| 101 | + --job short \ |
| 102 | + --exporters json \ |
| 103 | + --artifacts ./BenchmarkResults |
| 104 | + continue-on-error: true # Don't block the workflow; comparison step decides outcome |
| 105 | + |
| 106 | + - name: Compare results to baseline |
| 107 | + id: compare |
| 108 | + run: | |
| 109 | + python3 - << 'PYEOF' |
| 110 | + import json, os, sys, glob |
| 111 | +
|
| 112 | + REGRESSION_FACTOR = 3.0 # Fail if any benchmark is >3× baseline |
| 113 | + IMPROVEMENT_FACTOR = 0.8 # Celebrate 🎉 if any benchmark drops below 0.8× baseline |
| 114 | +
|
| 115 | + baseline_path = "Tests/Benchmarks/baseline.json" |
| 116 | + results_dir = "BenchmarkResults" |
| 117 | +
|
| 118 | + # --- Load baseline --- |
| 119 | + try: |
| 120 | + with open(baseline_path) as f: |
| 121 | + baseline_data = json.load(f) |
| 122 | + baseline = { |
| 123 | + f"{b['type']}/{b['method']}/{b['params']}": b["meanNs"] |
| 124 | + for b in baseline_data["benchmarks"] |
| 125 | + } |
| 126 | + except FileNotFoundError: |
| 127 | + print("::warning::baseline.json not found — skipping comparison") |
| 128 | + sys.exit(0) |
| 129 | +
|
| 130 | + # --- Find BenchmarkDotNet JSON results --- |
| 131 | + result_files = glob.glob(f"{results_dir}/**/*.json", recursive=True) |
| 132 | + result_files = [f for f in result_files if "results" in f.lower() or "report" in f.lower()] |
| 133 | + if not result_files: |
| 134 | + print("::warning::No BenchmarkDotNet result files found — skipping comparison") |
| 135 | + sys.exit(0) |
| 136 | +
|
| 137 | + # --- Parse results --- |
| 138 | + results = {} |
| 139 | + for fpath in result_files: |
| 140 | + try: |
| 141 | + with open(fpath) as f: |
| 142 | + data = json.load(f) |
| 143 | + for bm in data.get("Benchmarks", []): |
| 144 | + key = f"{bm['Type']}/{bm['Method']}/{bm.get('Parameters', '')}" |
| 145 | + results[key] = bm.get("Statistics", {}).get("Mean", None) |
| 146 | + except Exception as e: |
| 147 | + print(f"::warning::Could not parse {fpath}: {e}") |
| 148 | +
|
| 149 | + # --- Build comparison table --- |
| 150 | + rows = [] |
| 151 | + regressions = [] |
| 152 | + improvements = [] |
| 153 | +
|
| 154 | + for key, base_ns in baseline.items(): |
| 155 | + if base_ns <= 0: |
| 156 | + continue |
| 157 | + cur_ns = results.get(key) |
| 158 | + if cur_ns is None: |
| 159 | + rows.append(f"| {key} | {base_ns/1000:.1f} µs | — (not measured) | — |") |
| 160 | + continue |
| 161 | +
|
| 162 | + ratio = cur_ns / base_ns |
| 163 | + emoji = "✅" |
| 164 | + if ratio >= REGRESSION_FACTOR: |
| 165 | + emoji = "❌" |
| 166 | + regressions.append((key, base_ns, cur_ns, ratio)) |
| 167 | + elif ratio <= IMPROVEMENT_FACTOR: |
| 168 | + emoji = "🎉" |
| 169 | + improvements.append((key, base_ns, cur_ns, ratio)) |
| 170 | + rows.append( |
| 171 | + f"| {key} | {base_ns/1000:.1f} µs | {cur_ns/1000:.1f} µs | {ratio:.2f}× {emoji} |" |
| 172 | + ) |
| 173 | +
|
| 174 | + # --- Write step summary --- |
| 175 | + summary = "## 📊 Scrolling Benchmark Comparison\n\n" |
| 176 | + summary += "| Benchmark | Baseline | Current | Ratio |\n" |
| 177 | + summary += "|-----------|----------|---------|-------|\n" |
| 178 | + summary += "\n".join(rows) + "\n\n" |
| 179 | +
|
| 180 | + if improvements: |
| 181 | + summary += "### 🎉 Performance Improvements\n" |
| 182 | + for k, b, c, r in improvements: |
| 183 | + summary += f"- **{k}**: {b/1000:.1f} µs → {c/1000:.1f} µs ({r:.2f}×)\n" |
| 184 | + summary += "\n" |
| 185 | +
|
| 186 | + if regressions: |
| 187 | + summary += "### ❌ Regressions Detected\n" |
| 188 | + for k, b, c, r in regressions: |
| 189 | + summary += f"- **{k}**: {b/1000:.1f} µs → {c/1000:.1f} µs ({r:.2f}×) — exceeds {REGRESSION_FACTOR}× threshold\n" |
| 190 | + summary += "\n" |
| 191 | +
|
| 192 | + with open(os.environ.get("GITHUB_STEP_SUMMARY", "/dev/null"), "a") as f: |
| 193 | + f.write(summary) |
| 194 | +
|
| 195 | + print(summary) |
| 196 | +
|
| 197 | + if regressions: |
| 198 | + print(f"::error::Performance regressions detected: {len(regressions)} benchmark(s) exceeded {REGRESSION_FACTOR}× baseline") |
| 199 | + sys.exit(1) |
| 200 | +
|
| 201 | + if improvements: |
| 202 | + print(f"Performance improvements detected: {len(improvements)} benchmark(s) improved!") |
| 203 | + PYEOF |
| 204 | +
|
| 205 | + - name: Upload benchmark results |
| 206 | + if: always() |
| 207 | + uses: actions/upload-artifact@v7 |
| 208 | + with: |
| 209 | + name: benchmark-results-${{ github.sha }} |
| 210 | + path: BenchmarkResults/ |
| 211 | + if-no-files-found: ignore |
| 212 | + retention-days: 30 |
0 commit comments