build-perf-baseline
它能做什么
这项技能为 .NET 项目设置公平的构建计时测量,使改进可以被证明。适合希望在改动任何东西之前,先了解构建到底有多慢的团队。
适用场景
- ✓当 .NET 构建很慢,并且你希望在改动前获得可靠数字时。
- ✓当你想比较某项改动前后的构建时。
- ✓当你希望分别测量冷构建、热构建和无改动构建的时候。
技能链接
https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/build-perf-baseline/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请测量我的 .NET 解决方案冷构建以及小改动之后的构建耗时,以便我们建立基线。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会让每次运行的设置保持一致,把每个场景重复多次,为每个样本保存日志,并报告中位数和范围。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Build Performance Baseline & Optimization
Overview
Before optimizing a build, you need a baseline. Without measurements, optimization is guesswork. This skill covers how to establish baselines and apply systematic optimization techniques.
Related skills:
build-perf-diagnostics— binlog-based bottleneck identificationincremental-build— Inputs/Outputs and up-to-date checksbuild-parallelism— parallel and graph build tuningeval-performance— glob and import chain optimization
Step 1: Establish a Performance Baseline
Measure three scenarios to understand where time is spent. Keep the SDK, configuration, machine, environment variables, restore state, and build command consistent. Run each scenario at least three times, repeating its setup before every measured sample, and report the median plus the observed range; a single timing is not a baseline. Keep setup outside the timed interval. Save each sample's binlog under a unique name, outside generated output directories.
Cold Build (First Build)
No previous build output exists. Measures the full end-to-end time including restore, compilation, and all targets.
Before every cold sample, restore the same source state, run dotnet clean
with the measured configuration, and remove only the confirmed, disposable
output and intermediate directories for the measured projects. Include custom
artifact paths, not just bin and obj, and obtain approval before deletion.
Verify those outputs are absent before timing the next build.
This is an output-cold build, not necessarily a cold NuGet, OS, or compiler server cache. Choose and record a consistent cache/server policy for all samples; do not clear shared caches. If measuring uncached restore, use a separate, empty package cache for each sample.
# After repeating the cold setup; use a unique log name for each sample
dotnet build /bl:cold-build-1.binlog -m
Warm Build (Incremental Build)
Build output exists, some files have changed. Measures how well incremental build works.
Before every warm sample, restore the same baseline source contents and build successfully without timing it. Then apply the same small, build-relevant edit to the same source file and time the build. Keep the changed file set and edit identical across samples; do not let edits accumulate. Restore the baseline contents before the next sample and rebuild them outside the timed interval. Do not clean between that setup build and its measured build.
# Untimed setup after restoring baseline source contents
dotnet build -m
# Apply the same controlled source edit, then measure with a unique log name
dotnet build /bl:warm-build-1.binlog -m
No-Op Build (Nothing Changed)
Build output exists, nothing has changed. Compilation and correctly incremental targets should skip; compare timing with this build's other samples.
Before every no-op sample, restore the same baseline source contents and run an untimed setup build successfully. Then measure an identical build without edits, touching inputs, cleaning outputs, or changing properties. Keep restore and cache/server policy consistent with the other samples.
# Untimed setup after restoring baseline source contents
dotnet build -m
# Rebuild immediately without changes; use a unique log name for each sample
dotnet build /bl:noop-build-1.binlog -m
What Good Looks Like
| Scenario | Expected Behavior |
|---|---|
| Cold build | Full compilation, all targets run. This is your absolute baseline |
| Warm build | Only changed projects recompile. Time proportional to change scope |
| No-op build | Compilation and correctly incremental custom targets skip; compare duration with this repo's repeated warm and cold samples |
Red flags:
- No-op time is repeatedly close to warm/cold time, or compilation targets rerun → investigate incrementality (see
incremental-build) - Warm build recompiles everything → project dependency chain forces full rebuild
- Restore dominates cold samples → measure
dotnet restoreanddotnet build --no-restoreseparately before changing project structure
Do not use universal duration or percentage thresholds to declare a bottleneck. Rank costs against the controlled samples and the build's own target/task timings.
Capture analyzer evidence
A binlog shows compiler/task timing, but granular analyzer timing requires an analyzer-reporting run. When su
常见问题
为什么要把每个场景运行多次?
单次计时可能有很大波动,多次运行可以得到带有范围的公平基线。
什么是冷构建?
冷构建是没有任何先前输出的第一次构建,包括还原和全部编译。
它会修复缓慢的构建吗?
不会。它先进行测量,原因由诊断技能找出。
详情
作者的原始描述
Establish MSBuild/.NET build performance baselines before optimizing. USE FOR: unranked slow builds; cold, warm, incremental or no-op measurements; before/after comparisons; CI output caching; static graph, artifacts output and dependency graph trimming. Start here before build-perf-diagnostics, incremental-build or build-parallelism. DO NOT USE FOR: known repeated-restore fixes (use eliminate-redundant-restores), non-MSBuild builds. For measured target/task/analyzer bottlenecks, use build-perf-diagnostics.
repo: dotnet/skills
热度
- GitHub 星标
- 5.8k
- 排名
- #14593
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
create-custom-agent
5.8k帮你的智能体创建 VS Code 自定义智能体文件,为每个智能体设置专属工具、指令以及向其他智能体的交接。
create-skill
5.8k帮你的智能体创建新的智能体技能,包括有效的名称、清晰的触发描述,以及符合标准的 SKILL.md 文件。
csharp-scripts
5.8k帮你的智能体通过 .NET 命令行工具以单个文件运行小型 C# 程序,无需创建完整项目。
dotnet-pinvoke
5.8k帮你的智能体在 .NET 中正确调用原生 C 或 C++ 库,涵盖函数签名、字符串处理、内存和安全句柄。