Skip to content

Commit 7d96c67

Browse files
authored
Fix npm audit and partition benchmark history by environment (#293)
1 parent 441610b commit 7d96c67

11 files changed

Lines changed: 290 additions & 34 deletions

‎.github/workflows/benchmark-regression.yml‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ permissions:
3333
jobs:
3434
benchmark-regression:
3535
runs-on: ubuntu-latest
36+
outputs:
37+
benchmark-suite: ${{ steps.combine.outputs.suite }}
3638
steps:
3739
- name: Checkout
3840
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -59,26 +61,12 @@ jobs:
5961
run: dotnet run --project FolderDiffIL4DotNet.Benchmarks/FolderDiffIL4DotNet.Benchmarks.csproj --configuration Release -- --exporters json --filter '*'
6062

6163
- name: Combine benchmark results
64+
id: combine
6265
run: |
63-
python3 - <<'PY'
64-
import json, glob, sys
65-
66-
combined = []
67-
for path in sorted(glob.glob("BenchmarkDotNet.Artifacts/results/*-report-full-compressed.json")):
68-
with open(path) as f:
69-
data = json.load(f)
70-
if "Benchmarks" in data:
71-
combined.extend(data["Benchmarks"])
72-
73-
if not combined:
74-
print("No benchmark results found.", file=sys.stderr)
75-
sys.exit(1)
76-
77-
with open("BenchmarkDotNet.Artifacts/results/combined-report.json", "w") as f:
78-
json.dump({"Benchmarks": combined}, f, indent=2)
79-
80-
print(f"Combined {len(combined)} benchmark(s).")
81-
PY
66+
python3 scripts/benchmark_environment.py \
67+
--results-directory BenchmarkDotNet.Artifacts/results \
68+
--policy benchmark-regression-policy.json \
69+
--github-output "$GITHUB_OUTPUT"
8270
8371
- name: Check if baseline branch exists
8472
id: check-baseline
@@ -189,7 +177,7 @@ jobs:
189177
- name: Publish trusted benchmark baseline
190178
uses: benchmark-action/github-action-benchmark@52576c92bccf6ac60c8223ec7eb2565637cae9ba # v1.22.1
191179
with:
192-
name: 'FolderDiffIL4DotNet Performance'
180+
name: ${{ needs.benchmark-regression.outputs.benchmark-suite }}
193181
tool: 'benchmarkdotnet'
194182
output-file-path: BenchmarkDotNet.Artifacts/results/combined-report.json
195183
github-token: ${{ secrets.GITHUB_TOKEN }}

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
99

1010
### [Unreleased]
1111

12+
#### Fixed
13+
14+
- **npm audit CI uses patched js-yaml** — Updated the 3.x override and lockfile to `3.15.2`, resolving `GHSA-2883-xcg3-v3hh` without adding an audit exception.
15+
- **Benchmark regression CI compares matching execution environments** — Preserved BenchmarkDotNet host metadata and partitioned trusted history by CPU, core topology, OS, architecture, runtime/SDK, build configuration, and BenchmarkDotNet version. Mixed-host legacy history starts a visible five-sample warmup per environment; warning/failure thresholds, ancestry checks, and trusted publication restrictions remain unchanged. Added regression coverage for environment isolation, invalid host metadata, report combination, and real slowdowns within one environment.
16+
1217
### [2.0.2] - 2026-09-05
1318

1419
#### Changed
@@ -1764,6 +1769,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
17641769

17651770
### [Unreleased]
17661771

1772+
#### 修正
1773+
1774+
- **npm audit CI で修正版 js-yaml を使用** — 3.x override と lockfile を `3.15.2` に更新し、監査例外を追加せず `GHSA-2883-xcg3-v3hh` を解消しました。
1775+
- **ベンチマーク回帰 CI を同一実行環境で比較** — BenchmarkDotNet のホスト情報を保持し、CPU、コア構成、OS、アーキテクチャ、runtime/SDK、ビルド構成、BenchmarkDotNet バージョンごとに信頼済み履歴を分離しました。旧来のホスト混在履歴は環境ごとに明示的な 5 サンプルのウォームアップから開始し、warning/failure 閾値、祖先チェック、信頼済み公開の制約は維持します。環境分離、不正なホスト情報、レポート結合、同一環境内での実際の遅化に回帰テストを追加しました。
1776+
17671777
### [2.0.2] - 2026-09-05
17681778

17691779
#### 変更

‎FolderDiffIL4DotNet.Tests/Architecture/CiAutomationConfigurationTests.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ public void BenchmarkRegressionWorkflow_DetectsPerformanceDegradation()
655655
Assert.Contains("FolderDiffIL4DotNet.Benchmarks", workflow, StringComparison.Ordinal);
656656
Assert.Contains("--exporters json", workflow, StringComparison.Ordinal);
657657
Assert.Contains("combined-report.json", workflow, StringComparison.Ordinal);
658+
Assert.Contains("scripts/benchmark_environment.py", workflow, StringComparison.Ordinal);
659+
Assert.Contains("benchmark-suite: ${{ steps.combine.outputs.suite }}", workflow, StringComparison.Ordinal);
660+
Assert.Contains("name: ${{ needs.benchmark-regression.outputs.benchmark-suite }}", workflow, StringComparison.Ordinal);
658661
Assert.Contains("scripts/check_benchmark_regressions.py", workflow, StringComparison.Ordinal);
659662
Assert.Contains("--policy benchmark-regression-policy.json", workflow, StringComparison.Ordinal);
660663
Assert.Contains("--baseline-ancestor \"${{ steps.benchmark-base.outputs.sha }}\"", workflow, StringComparison.Ordinal);

‎doc/PERFORMANCE_GUIDE.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks -- --filter *Fold
113113
The [`benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml) workflow:
114114
- Stores trusted baseline results in `gh-benchmarks` only after a successful push to `main`, or an explicit `publish_baseline` manual run on `main`.
115115
- Uses [`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) to compare each current mean with the median of the newest compatible hosted-runner samples. Compatibility requires the history commit to be an ancestor of the intended PR/push base plus the same benchmark-project/global SDK fingerprint and `baseline_revision`; incompatible history is excluded and counted in the Actions summary.
116+
- Preserves `HostEnvironmentInfo` when combining reports and stores each CPU model, core topology, OS, architecture, .NET runtime/SDK, build configuration, and BenchmarkDotNet version under a separate environment suite. The gate reads only that suite; old history without host metadata is not reused. Missing or inconsistent current host metadata fails the run. The environment suite is shown in the Actions summary, and host metadata is retained in the report artifact.
116117
- Reads warning/failure limits from [`benchmark-regression-policy.json`](../benchmark-regression-policy.json). Warnings remain non-blocking, failures block CI, and every benchmark result and threshold is visible in the Actions summary.
117118

118119
The initial policy is based on seven `ubuntu-latest` runs from 2026-07-25 (`c2796a65` through `4b32a773`) whose benchmark definitions and .NET SDK selection were identical. The median reduces runner outliers. For each stability group, the warning limit is the largest observed slowdown rounded up to 5 percentage points plus a 5-point guard band; the failure limit is twice the warning limit.
@@ -125,7 +126,7 @@ The initial policy is based on seven `ubuntu-latest` runs from 2026-07-25 (`c279
125126
| Standard text diff | 14.0% | 20% | 40% |
126127
| Million-line text diff | 42.7% | 50% | 100% |
127128

128-
At least five compatible samples are required; otherwise the affected benchmark is reported as `WARMUP` instead of being compared silently. When a benchmark definition or `global.json` changes, merge the reviewed change, let the `main` push publish the first new baseline, then run the workflow on `main` four more times with `publish_baseline=true`. For an intentional baseline reset without a definition change, increment `baseline_revision` first and follow the same process. Manual publication keeps detected failures visible but non-blocking so an explicitly accepted baseline can be rebuilt. Re-measure hosted-runner variance and update the evidence, thresholds, and changelog when runner images or benchmark behavior materially change.
129+
At least five compatible samples are required; otherwise the affected benchmark is reported as `WARMUP` instead of being compared silently. When a benchmark definition or `global.json` changes, merge the reviewed change, let the `main` push publish the first new baseline, then collect at least four more compatible runs in the same environment, using subsequent `main` pushes or explicit `publish_baseline=true` runs on `main`. Hosted runners may use different CPUs, so more than four additional workflow runs can be needed. New environments and the migration from mixed-host history also start in `WARMUP`. For an intentional baseline reset without a definition change, increment `baseline_revision` first and follow the same process. Manual publication keeps detected failures visible but non-blocking so an explicitly accepted baseline can be rebuilt. Re-measure hosted-runner variance and update the evidence, thresholds, and changelog when runner images or benchmark behavior materially change.
129130

130131
<a id="perf-en-tuning"></a>
131132
## Tuning Recommendations
@@ -256,6 +257,7 @@ dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks -- --filter *Fold
256257
[`benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml) ワークフロー:
257258
- `main` への push が成功した場合、または `main` 上で `publish_baseline` を明示した手動実行の場合だけ、信頼済みベースラインを `gh-benchmarks` に保存します。
258259
- [`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) が、現在の各 mean を互換 hosted-runner サンプルの新しい方から得た中央値と比較します。互換性には、履歴コミットが意図した PR/push の base の祖先であること、ベンチマークプロジェクト/global SDK の同一フィンガープリント、`baseline_revision` を要求し、非互換履歴は除外して Actions summary に件数を表示します。
260+
- レポート結合時に `HostEnvironmentInfo` を保持し、CPU モデル、コア構成、OS、アーキテクチャ、.NET runtime/SDK、ビルド構成、BenchmarkDotNet バージョンごとに独立した環境 suite へ保存します。ゲートは一致する suite のみ読み込み、ホスト情報のない旧履歴は再利用しません。現在のホスト情報が欠落または不一致なら実行を失敗させます。環境 suite は Actions summary に表示し、ホスト情報はレポート artifact に保持します。
259261
- [`benchmark-regression-policy.json`](../benchmark-regression-policy.json) から warning/failure 上限を読み込みます。warning は非ブロッキング、failure は CI をブロックし、すべてのベンチマーク結果と閾値を Actions summary に表示します。
260262

261263
初期ポリシーは、ベンチマーク定義と .NET SDK 選択が同一だった 2026-07-25 の `ubuntu-latest` 7 実行(`c2796a65`~`4b32a773`)に基づきます。runner の外れ値を抑えるため中央値を使用します。各安定性グループの warning は、観測された最大遅化を 5 ポイント単位で切り上げ、さらに 5 ポイントの余裕を加えた値です。failure は warning の 2 倍です。
@@ -268,7 +270,7 @@ dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks -- --filter *Fold
268270
| 標準テキスト差分 | 14.0% | 20% | 40% |
269271
| 100 万行テキスト差分 | 42.7% | 50% | 100% |
270272

271-
互換サンプルが 5 件未満の場合、そのベンチマークを暗黙に比較せず `WARMUP` として報告します。ベンチマーク定義または `global.json` を変更した場合は、レビュー済み変更をマージし、`main` push で最初の新ベースラインを公開した後、`main` 上で `publish_baseline=true` を指定してワークフローをさらに 4 回実行します。定義変更なしで意図的にベースラインをリセットする場合は、先に `baseline_revision` を増やして同じ手順を実施します。手動公開モードでも failure は表示しますが、明示的に受け入れたベースラインを再構築できるよう非ブロッキングにします。runner image またはベンチマーク挙動が大きく変わった場合は hosted-runner 分散を再計測し、根拠、閾値、CHANGELOG を更新します。
273+
互換サンプルが 5 件未満の場合、そのベンチマークを暗黙に比較せず `WARMUP` として報告します。ベンチマーク定義または `global.json` を変更した場合は、レビュー済み変更をマージし、`main` push で最初の新ベースラインを公開した後、その後の `main` push または `main` 上の明示的な `publish_baseline=true` 実行で、同じ環境の互換サンプルをさらに 4 件以上集めます。hosted runner は異なる CPU を使用する場合があるため、追加実行が 4 回を超えることがあります。新しい環境やホスト混在履歴からの移行時も `WARMUP` から開始します。定義変更なしで意図的にベースラインをリセットする場合は、先に `baseline_revision` を増やして同じ手順を実施します。手動公開モードでも failure は表示しますが、明示的に受け入れたベースラインを再構築できるよう非ブロッキングにします。runner image またはベンチマーク挙動が大きく変わった場合は hosted-runner 分散を再計測し、根拠、閾値、CHANGELOG を更新します。
272274

273275
<a id="perf-ja-tuning"></a>
274276
## チューニング推奨

‎doc/TESTING_GUIDE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks
161161
dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks -- --filter *TextDiffer*
162162
```
163163

164-
The `benchmark` CI job (workflow_dispatch only) runs all benchmarks with JSON and GitHub exporters and uploads `BenchmarkDotNet.Artifacts/` as a CI artifact. The `benchmark-regression` workflow ([`.github/workflows/benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml)) runs automatically on PRs to `main`. [`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) uses a compatible-history median and the evidence-based per-group warning/failure limits in [`benchmark-regression-policy.json`](../benchmark-regression-policy.json). Controlled Python fixtures exercise median calculation, exact threshold boundaries, intended-base ancestry, warmup/reset behavior, definition mismatch, and intentional baseline publication; run them with the `python3 -m unittest discover` command above.
164+
The `benchmark` CI job (workflow_dispatch only) runs all benchmarks with JSON and GitHub exporters and uploads `BenchmarkDotNet.Artifacts/` as a CI artifact. The `benchmark-regression` workflow ([`.github/workflows/benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml)) runs automatically on PRs to `main`. [`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) uses a compatible-history median and the evidence-based per-group warning/failure limits in [`benchmark-regression-policy.json`](../benchmark-regression-policy.json). Controlled Python fixtures exercise median calculation, exact threshold boundaries, intended-base ancestry, warmup/reset behavior, definition mismatch, environment isolation, missing/mixed host rejection, report combination, and intentional baseline publication; run them with the `python3 -m unittest discover` command above.
165165

166166
CI-parity command (same as GitHub Actions test step):
167167

@@ -415,7 +415,7 @@ dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks
415415
dotnet run -c Release --project FolderDiffIL4DotNet.Benchmarks -- --filter *TextDiffer*
416416
```
417417

418-
`benchmark` CI ジョブ(workflow_dispatch のみ)はすべてのベンチマークを JSON および GitHub エクスポーター付きで実行し、`BenchmarkDotNet.Artifacts/` を CI アーティファクトとしてアップロードします。`benchmark-regression` ワークフロー([`.github/workflows/benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml))は `main` への PR で自動実行されます。[`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) が互換履歴の中央値と [`benchmark-regression-policy.json`](../benchmark-regression-policy.json) の実測ベースなグループ別 warning/failure 上限を使用します。制御された Python fixture で中央値計算、正確な閾値境界、意図した base の祖先判定、warmup/reset、定義不一致、意図的 baseline 公開を検証します。上記の `python3 -m unittest discover` コマンドで実行できます。
418+
`benchmark` CI ジョブ(workflow_dispatch のみ)はすべてのベンチマークを JSON および GitHub エクスポーター付きで実行し、`BenchmarkDotNet.Artifacts/` を CI アーティファクトとしてアップロードします。`benchmark-regression` ワークフロー([`.github/workflows/benchmark-regression.yml`](../.github/workflows/benchmark-regression.yml))は `main` への PR で自動実行されます。[`scripts/check_benchmark_regressions.py`](../scripts/check_benchmark_regressions.py) が互換履歴の中央値と [`benchmark-regression-policy.json`](../benchmark-regression-policy.json) の実測ベースなグループ別 warning/failure 上限を使用します。制御された Python fixture で中央値計算、正確な閾値境界、意図した base の祖先判定、warmup/reset、定義不一致、環境ごとの分離、ホスト情報の欠落・混在拒否、レポート結合、意図的 baseline 公開を検証します。上記の `python3 -m unittest discover` コマンドで実行できます。
419419

420420
CI 同等コマンド(GitHub Actions と同じ test ステップ):
421421

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"overrides": {
2525
"brace-expansion@<1.1.18": "1.1.18",
2626
"brace-expansion@>=2.0.0 <2.1.4": "2.1.4",
27-
"js-yaml@>=3.0.0 <3.15.1": "3.15.1"
27+
"js-yaml@>=3.0.0 <3.15.2": "3.15.2"
2828
}
2929
}

0 commit comments

Comments
 (0)