Skip to content

Commit c5f8770

Browse files
pelikhanCopilot
andauthored
ci: isolate and shard main-only Go benchmarks (#79278)
Move benchmarks out of CGO and PR suite selection. Run four independent benchmark shards, avoid external scanner timings, and bound workqueue replay iterations while retaining every ledger size. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 097f67b commit c5f8770

7 files changed

Lines changed: 227 additions & 183 deletions

File tree

‎.github/ci/suite-catalog.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"historical_duration_seconds": null,
4646
"mandatory": false
4747
},
48-
{ "id": "bench", "description": "Run Go benchmarks and compare with historical baselines using benchstat for runtime performance regressions.", "historical_duration_seconds": null, "mandatory": false },
4948
{ "id": "check-validator-sizes", "description": "Run the validator source file-size checker; report oversized validation Go files.", "historical_duration_seconds": null, "mandatory": false },
5049
{ "id": "lint-go-format", "description": "Check formatting of Go source and test files with repository Go formatting commands.", "historical_duration_seconds": null, "mandatory": false },
5150
{ "id": "lint-go-golangci", "description": "Run golangci-lint on Go packages in three shards, including compiler, CLI, internal tools, test files, and lint configuration.", "historical_duration_seconds": null, "mandatory": false },

‎.github/workflows/benchmarks.yml‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Benchmarks
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '**/*.go'
8+
- 'go.mod'
9+
- 'go.sum'
10+
- 'Makefile'
11+
- '.github/workflows/benchmarks.yml'
12+
schedule:
13+
- cron: '23 4 * * 1'
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
actions: read
19+
20+
concurrency:
21+
group: benchmarks-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
bench:
26+
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 15
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
shard: [cli, workflow, workqueue, other]
33+
env:
34+
SHARD: ${{ matrix.shard }}
35+
ARTIFACT_NAME: benchmark-results-${{ matrix.shard }}
36+
# Scanner integration is covered by CGO; do not benchmark Docker pulls or timeouts.
37+
BENCH_SKIP: '^BenchmarkCompile(With(Zizmor|Poutine|AllSecurityTools)|ComplexWithSecurityTools)$'
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
41+
with:
42+
persist-credentials: false
43+
44+
- name: Set up Go
45+
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6
46+
with:
47+
go-version-file: go.mod
48+
cache: true
49+
50+
- name: Run benchmarks
51+
id: benchmarks
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
# Only compile packages containing benchmarks, not every linter/test package.
56+
benchmark_files=$(git grep -l '^func Benchmark' -- 'pkg/*_test.go')
57+
packages=$(printf '%s\n' "$benchmark_files" | xargs dirname | sort -u)
58+
selected=()
59+
while IFS= read -r package; do
60+
case "$package" in
61+
pkg/cli) shard=cli ;;
62+
pkg/workflow|pkg/workflow/*) shard=workflow ;;
63+
pkg/workqueue) shard=workqueue ;;
64+
*) shard=other ;;
65+
esac
66+
if [ "$shard" = "$SHARD" ]; then
67+
selected+=("./$package")
68+
fi
69+
done <<< "$packages"
70+
if [ "${#selected[@]}" -eq 0 ]; then
71+
echo "::error::No benchmark packages found for $SHARD"
72+
exit 1
73+
fi
74+
benchtime=3x
75+
# Each replay already takes seconds; retain every ledger size with one iteration.
76+
if [ "$SHARD" = workqueue ]; then
77+
benchtime=1x
78+
fi
79+
make bench BENCH_PACKAGES="${selected[*]}" BENCH_TIME="$benchtime"
80+
{
81+
echo "## Benchmark results: $SHARD"
82+
echo '```'
83+
grep '^Benchmark' bench_results.txt
84+
echo '```'
85+
} >> "$GITHUB_STEP_SUMMARY"
86+
87+
- name: Download previous benchmark baseline
88+
id: baseline
89+
env:
90+
GH_TOKEN: ${{ github.token }}
91+
shell: bash
92+
run: |
93+
set -euo pipefail
94+
artifacts=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$ARTIFACT_NAME&per_page=100")
95+
artifact_id=$(jq -r --arg run_id "$GITHUB_RUN_ID" \
96+
'[.artifacts[] | select(.expired == false and .workflow_run.head_branch == "main" and (.workflow_run.id | tostring) != $run_id)] | .[0].id // empty' <<< "$artifacts")
97+
if [ -z "$artifact_id" ]; then
98+
echo "No previous $ARTIFACT_NAME baseline; this run establishes it." >> "$GITHUB_STEP_SUMMARY"
99+
echo "has_baseline=false" >> "$GITHUB_OUTPUT"
100+
else
101+
gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact_id/zip" > baseline.zip
102+
unzip -q baseline.zip -d baseline
103+
test -s baseline/bench_results.txt
104+
echo "has_baseline=true" >> "$GITHUB_OUTPUT"
105+
fi
106+
107+
- name: Install benchstat
108+
if: steps.baseline.outputs.has_baseline == 'true'
109+
run: go install golang.org/x/perf/cmd/benchstat@v0.0.0-20260615155930-9e4b9ddef5b6
110+
111+
- name: Run benchstat regression check
112+
if: steps.baseline.outputs.has_baseline == 'true'
113+
shell: bash
114+
run: |
115+
set -euo pipefail
116+
benchstat_out=$(benchstat baseline/bench_results.txt bench_results.txt)
117+
echo "$benchstat_out"
118+
{
119+
echo "## Benchmark regression check: $SHARD"
120+
echo '```'
121+
echo "$benchstat_out"
122+
echo '```'
123+
} >> "$GITHUB_STEP_SUMMARY"
124+
regression=false
125+
while IFS= read -r line; do
126+
if [[ "$line" =~ \+([0-9]+(\.[0-9]+)?)% ]]; then
127+
if awk -v p="${BASH_REMATCH[1]}" 'BEGIN {exit !(p > 10)}'; then
128+
echo "::error::Performance regression >10%: $line"
129+
regression=true
130+
fi
131+
fi
132+
done <<< "$benchstat_out"
133+
if [ "$regression" = true ]; then
134+
exit 1
135+
fi
136+
137+
- name: Save benchmark results
138+
if: always() && steps.benchmarks.outcome == 'success'
139+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
140+
with:
141+
name: ${{ env.ARTIFACT_NAME }}
142+
path: bench_results.txt
143+
if-no-files-found: error
144+
retention-days: 14

‎.github/workflows/cgo.yml‎

Lines changed: 1 addition & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
run: |
131131
node <<'NODE'
132132
const fs = require('node:fs');
133-
const known = ['front-door-conformance', 'verify-integration-build', 'test', 'canary-go', 'impacted-go-tests', 'native-javascript-tests', 'build', 'build-wasm', 'validate-yaml', 'bench', 'check-validator-sizes', 'lint-go-format', 'lint-go-golangci', 'lint-go-govulncheck', 'lint-go-custom', 'lint-error-messages', 'actions-build', 'fuzz', 'security', 'security-scan', 'mcp-server-compile-test', 'cross-platform-build', 'alpine-container-test', 'safe-outputs-conformance'];
133+
const known = ['front-door-conformance', 'verify-integration-build', 'test', 'canary-go', 'impacted-go-tests', 'native-javascript-tests', 'build', 'build-wasm', 'validate-yaml', 'check-validator-sizes', 'lint-go-format', 'lint-go-golangci', 'lint-go-govulncheck', 'lint-go-custom', 'lint-error-messages', 'actions-build', 'fuzz', 'security', 'security-scan', 'mcp-server-compile-test', 'cross-platform-build', 'alpine-container-test', 'safe-outputs-conformance'];
134134
const dependencies = {test: ['verify-integration-build'], 'canary-go': ['test'], security: ['build'], 'security-scan': ['build'], 'cross-platform-build': ['build']};
135135
let suiteIds = '';
136136
try {
@@ -1278,182 +1278,6 @@ jobs:
12781278
12791279
core.info(`✅ ${CONFIG_FILE} passes all structural and cross-row invariant checks`);
12801280
1281-
bench:
1282-
# PR relevance comes from frontdoor; retain main-only performance tracking otherwise.
1283-
if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/main') && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'bench'))
1284-
needs: [checkout-cache, front-door-decision]
1285-
runs-on: ubuntu-latest
1286-
timeout-minutes: 20
1287-
permissions:
1288-
contents: read
1289-
actions: read
1290-
concurrency:
1291-
group: ci-${{ github.ref }}-bench
1292-
cancel-in-progress: true
1293-
steps:
1294-
- name: Restore checkout
1295-
id: restore-checkout
1296-
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
1297-
with:
1298-
path: .
1299-
key: checkout-cgo-${{ github.run_id }}-${{ github.sha }}
1300-
- name: Checkout on cache miss
1301-
if: steps.restore-checkout.outputs.cache-hit != 'true'
1302-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1303-
with:
1304-
ref: ${{ github.sha }}
1305-
fetch-depth: 2
1306-
persist-credentials: false
1307-
1308-
- name: Set up Go
1309-
id: setup-go
1310-
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6
1311-
with:
1312-
go-version-file: go.mod
1313-
cache: true
1314-
1315-
- name: Report Go cache status
1316-
run: |
1317-
if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then
1318-
echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY
1319-
else
1320-
echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY
1321-
fi
1322-
1323-
- name: Download dependencies with retry
1324-
if: steps.setup-go.outputs.cache-hit != 'true'
1325-
run: |
1326-
set -e
1327-
MAX_RETRIES=3
1328-
RETRY_DELAY=5
1329-
1330-
for i in $(seq 1 $MAX_RETRIES); do
1331-
echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..."
1332-
if go mod download; then
1333-
echo "✅ Successfully downloaded Go modules"
1334-
break
1335-
else
1336-
if [ $i -eq $MAX_RETRIES ]; then
1337-
echo "❌ Failed to download Go modules after $MAX_RETRIES attempts"
1338-
echo "This may indicate that proxy.golang.org is unreachable"
1339-
echo "Please check network connectivity or consider vendoring dependencies"
1340-
exit 1
1341-
fi
1342-
echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..."
1343-
sleep $RETRY_DELAY
1344-
fi
1345-
done
1346-
1347-
- name: Verify dependencies
1348-
run: go mod verify
1349-
1350-
- name: Install benchstat
1351-
run: go install golang.org/x/perf/cmd/benchstat@v0.0.0-20260615155930-9e4b9ddef5b6
1352-
1353-
- name: Download previous benchmark baseline
1354-
id: baseline
1355-
env:
1356-
GH_TOKEN: ${{ github.token }}
1357-
run: |
1358-
set +e
1359-
echo "Looking for previous benchmark-results artifact..."
1360-
# The bench job only runs on main, so any benchmark-results artifact is from main.
1361-
# The artifacts API includes workflow_run.head_branch; filter for main as an extra safeguard.
1362-
artifact_id=$(gh api \
1363-
"repos/$GITHUB_REPOSITORY/actions/artifacts?name=benchmark-results&per_page=10" \
1364-
--jq '[.artifacts[] | select(.workflow_run.head_branch? == "main")] | .[0].id // empty' 2>/dev/null)
1365-
1366-
if [ -n "$artifact_id" ]; then
1367-
echo "Found artifact ID: $artifact_id"
1368-
mkdir -p baseline
1369-
if gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact_id/zip" \
1370-
--output baseline.zip 2>/dev/null; then
1371-
if unzip -q baseline.zip -d baseline 2>/dev/null && [ -f baseline/bench_results.txt ]; then
1372-
echo "✅ Downloaded baseline benchmark results"
1373-
echo "has_baseline=true" >> "$GITHUB_OUTPUT"
1374-
else
1375-
echo "⚠️ Failed to extract baseline artifact or bench_results.txt not found"
1376-
echo "has_baseline=false" >> "$GITHUB_OUTPUT"
1377-
fi
1378-
else
1379-
echo "⚠️ Failed to download baseline artifact"
1380-
echo "has_baseline=false" >> "$GITHUB_OUTPUT"
1381-
fi
1382-
else
1383-
echo "ℹ️ No previous benchmark results found — skipping regression check on first run"
1384-
echo "has_baseline=false" >> "$GITHUB_OUTPUT"
1385-
fi
1386-
1387-
- name: Run benchmarks
1388-
run: make bench
1389-
1390-
- name: Run benchstat regression check
1391-
if: steps.baseline.outputs.has_baseline == 'true'
1392-
run: |
1393-
echo "## 📈 Benchmark Regression Check" >> $GITHUB_STEP_SUMMARY
1394-
echo "" >> $GITHUB_STEP_SUMMARY
1395-
1396-
if ! benchstat_out=$(benchstat baseline/bench_results.txt bench_results.txt 2>&1); then
1397-
echo "$benchstat_out"
1398-
echo '```' >> $GITHUB_STEP_SUMMARY
1399-
echo "$benchstat_out" >> $GITHUB_STEP_SUMMARY
1400-
echo '```' >> $GITHUB_STEP_SUMMARY
1401-
echo "" >> $GITHUB_STEP_SUMMARY
1402-
echo "❌ **benchstat failed to compare benchmark results.** Check the output above." >> $GITHUB_STEP_SUMMARY
1403-
echo "::error::benchstat failed to compare benchmark results"
1404-
exit 1
1405-
fi
1406-
1407-
echo "$benchstat_out"
1408-
1409-
echo '```' >> $GITHUB_STEP_SUMMARY
1410-
echo "$benchstat_out" >> $GITHUB_STEP_SUMMARY
1411-
echo '```' >> $GITHUB_STEP_SUMMARY
1412-
1413-
# Fail if any benchmark regresses by more than 10%.
1414-
# benchstat uses + for slower time (regression) and - for faster time (improvement).
1415-
REGRESSION=false
1416-
while IFS= read -r line; do
1417-
if [[ "$line" =~ \+([0-9]+(\.[0-9]+)?)% ]]; then
1418-
pct="${BASH_REMATCH[1]}"
1419-
if awk -v p="$pct" 'BEGIN {exit !(p > 10)}'; then
1420-
echo "❌ Regression: $line"
1421-
REGRESSION=true
1422-
fi
1423-
fi
1424-
done <<< "$benchstat_out"
1425-
1426-
if [ "$REGRESSION" = "true" ]; then
1427-
echo "" >> $GITHUB_STEP_SUMMARY
1428-
echo "❌ **Performance regression >10% detected.** See comparison above." >> $GITHUB_STEP_SUMMARY
1429-
echo "::error::Performance regression >10% detected — see benchstat output above"
1430-
exit 1
1431-
else
1432-
echo "" >> $GITHUB_STEP_SUMMARY
1433-
echo "✅ No significant performance regressions detected." >> $GITHUB_STEP_SUMMARY
1434-
echo "✅ No regressions detected"
1435-
fi
1436-
1437-
- name: Display benchmark summary
1438-
run: |
1439-
echo "## 📊 Benchmark Results" >> $GITHUB_STEP_SUMMARY
1440-
echo "" >> $GITHUB_STEP_SUMMARY
1441-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
1442-
# Show compiler benchmarks from the results
1443-
grep "BenchmarkCompile" bench_results.txt | head -20 >> $GITHUB_STEP_SUMMARY || echo "No benchmark results found" >> $GITHUB_STEP_SUMMARY
1444-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
1445-
echo "" >> $GITHUB_STEP_SUMMARY
1446-
echo "📁 Full results saved to artifact: benchmark-results" >> $GITHUB_STEP_SUMMARY
1447-
1448-
# Benchmark results for performance trend analysis - 14 days allows comparison across multiple runs
1449-
- name: Save benchmark results
1450-
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
1451-
with:
1452-
name: benchmark-results
1453-
path: bench_results.txt
1454-
if-no-files-found: ignore
1455-
retention-days: 14
1456-
14571281
check-validator-sizes:
14581282
name: Check validator file sizes
14591283
needs: [checkout-cache, front-door-decision]
@@ -3031,7 +2855,6 @@ jobs:
30312855
- build
30322856
- build-wasm
30332857
- validate-yaml
3034-
- bench
30352858
- check-validator-sizes
30362859
- lint-go-format
30372860
- lint-go-golangci

‎CONTRIBUTING.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,23 @@ Quick reference:
557557
### CI Front Door
558558

559559
CGO filters every check job on PRs through `scripts/ci-front-door.cjs`, including
560-
Go tests, security checks, linters, conformance, builds, benchmarks, fuzzing, and
560+
Go tests, security checks, linters, conformance, builds, fuzzing, and
561561
both macOS and Windows. Only checkout, selection, and timing/cache cleanup are
562562
unconditional infrastructure. Main-branch pushes,
563563
manual runs, and the weekly scheduled control run all applicable suites without
564564
calling the Decision API. CJS and Windows CI are unchanged.
565565

566+
Benchmarks run separately in `.github/workflows/benchmarks.yml`, only on main
567+
pushes, weekly schedules, or manual main-branch runs, never on PRs. CLI,
568+
workflow, workqueue, and other benchmark packages run in parallel. Workqueue
569+
replay uses one iteration per size instead of three; all sizes are retained.
570+
Routine benchmarks exclude external Zizmor/Poutine scanner invocations, which
571+
can measure container startup or timeouts rather than Go performance; the
572+
separate CGO security scan is unchanged. `make bench` still runs the full set
573+
locally. Use `BENCH_PACKAGES`, `BENCH_TIME`, and `BENCH_SKIP` to narrow a run.
574+
Each shard publishes its own results and compares with its previous main-branch
575+
baseline; the first run establishes the new shard baseline.
576+
566577
The selector uses GitHub Decisions at
567578
`https://api.githubcopilot.com/v1/decisions` with model `gpt-6-luna-decisions`.
568579
Only the dedicated `front-door-decision` job has `copilot-requests: write`;

‎Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,14 @@ test-perf:
215215
exit $$EXIT_CODE
216216

217217
# Run benchmarks for performance testing
218+
BENCH_PACKAGES ?= ./pkg/...
219+
BENCH_TIME ?= 3x
220+
BENCH_SKIP ?= ^$$
218221
.PHONY: bench
222+
bench: SHELL := /bin/bash -eu -o pipefail
219223
bench:
220224
@echo "Running benchmarks..."
221-
go test -bench=. -benchmem -benchtime=3x -run=^$$ ./pkg/... | tee bench_results.txt
225+
go test -bench=. -benchmem -benchtime=$(BENCH_TIME) -count=1 -skip='$(BENCH_SKIP)' -run=^$$ $(BENCH_PACKAGES) | tee bench_results.txt
222226

223227
# Run only critical performance benchmarks for daily monitoring
224228
# Uses time-based -benchtime (not a fixed low iteration count) so that results are

0 commit comments

Comments
 (0)