High-Performance CI Playbook
Every millisecond in CI comes from five bottlenecks: unnecessary serial dependencies, process-spawn overhead, cache misses, heavy link/test thrashing, and expensive Windows/macOS runners. Here is how to eliminate all five with FastCi.
1. Design Shallow, Critical-Path DAGs
FastCi's scheduler ranks ready jobs by longest critical path (weight + downstream dependency chain). A flat graph with explicit weight lets slow compilation start on millisecond 0 while linters and generators fill remaining CPU cores.
- Split build from test: If a PR only touches a unit test file, a separate
build-libjob stays a 100% CAS hit. - Keep
needsminimal: Never makelintorformatdepend onbuildunless it reads generated headers. - Assign realistic
weightvalues: Put high weights (e.g.,100–500) on core library builds and link steps so the scheduler never delays them behind short 1-second jobs. - Decompose coarse monoliths: Two 20-second library targets + one 2-second link finishes in ~22s instead of 42s and doubles cache reuse.
2. Prefer Direct-Spawn cmd Over shell
cmd invokes posix_spawn / CreateProcessW directly with an argv array. shell spawns /bin/sh -c or cmd.exe /c on every invocation.
| Aspect | "cmd": [...] (Recommended) | "shell": "..." |
|---|---|---|
| Windows process overhead | Single CreateProcessW (~2–4 ms) | Extra cmd.exe + AV scan overhead (~15–40 ms) |
| Portability | Identical across Linux, macOS, Windows | Diverges between POSIX sh and Windows cmd.exe |
| Injection safety | No shell expansion / quoting bugs | Must carefully escape paths and spaces |
Reserve shell strictly for genuine pipes, redirects, or shell-builtin chains.
3. Cache-Key Hygiene & Deterministic Inputs
A build cache is only fast when its keys are both sound and stable:
- Narrow
inputswith exclusions: Use!build/**,!dist/**,!*.log, and!.git/**so unrelated docs or build artifacts never bust the cache key. - Put build-shaping files in
critical_inputs: PutCMakeLists.txt,Cargo.lock,package-lock.json, and compiler configs incritical_inputs. Even underverify_inputs: "sample", critical inputs are always verified strictly. - Pin the compiler with
toolchain_cmd: E.g.,["cc", "--version"]or["rustc", "--version"]. FastCi caches the probe output per run and folds it into the BLAKE3 key so runner image upgrades never serve ABI-incompatible binaries. - Use
scan_deps+include_dirs: Let FastCi's SIMD scanner trace transitive imports across 10 languages (C/C++, ASM, Rust, Go, Zig, Python, JS/TS, Java, C#, Swift) instead of globbing the entire repo. - Strip non-determinism: Pass
-ffile-prefix-map=$PWD=.(GCC/Clang) or/Brepro(MSVC), avoid embedding timestamps in build flags, and setSOURCE_DATE_EPOCHwhen archiving.
4. Tune verify_inputs for Your Repo Size
| Mode | Behavior | When to Use |
|---|---|---|
"fast" |
Trusts statcache (mtime_ns, size, inode) + NTFS USN journal with zero re-hashing on metadata match. |
Local developer workstations and large monorepos (10k+ files). |
"sample" |
Uses statcache for normal inputs, verifies a deterministic 64-file sample by content, and strictly hashes every critical_inputs entry. |
Recommended CI default — near-fast speed with strong tamper/clock-skew protection. |
"strict" |
Re-hashes every input byte on every run. | Release signing pipelines, reproducible build verification, and untrusted workspaces. |
5. Resource-Aware Scheduling (cpu_slots & mem_mb)
Blindly running N linkers or Rust crates in parallel causes OOM kills and swap thrashing on 4-core / 7 GB GitHub-hosted runners. FastCi tracks both CPU slots and RAM budget (max_ram_mb):
{
"$schema": "https://seregonwar.github.io/FastCi/schema/fastci.schema.json",
"name": "cpp-service",
"verify_inputs": "sample",
"max_ram_mb": 6144,
"jobs": [
{
"id": "compile-core",
"cmd": ["cmake", "--build", "build", "--target", "core", "--parallel"],
"cpu_slots": 2,
"mem_mb": 2048,
"weight": 120,
"critical_inputs": ["CMakeLists.txt"],
"scan_deps": ["src/core/engine.c"],
"include_dirs": ["include"],
"outputs": ["build/libcore.a"]
},
{
"id": "link-release",
"needs": ["compile-core"],
"cmd": ["cmake", "--build", "build", "--target", "app"],
"cpu_slots": 2,
"mem_mb": 3072,
"weight": 80,
"inputs": ["build/libcore.a"],
"outputs": ["build/app"]
}
]
}
6. Cutting Windows (2×) & macOS (10×) CI Costs
GitHub Actions bills Windows minutes at 2× and macOS minutes at 10× relative to Linux. Apply these rules to minimize minutes on expensive runners:
- Gate Windows & macOS behind a fast Linux pre-check: Run formatting, static analysis, and unit tests on
ubuntu-latestfirst; skip Windows/macOS jobs on broken commits. - Always use Ninja + MSVC
/Z7on Windows: Never use MSBuild solution builds when Ninja works, and never pass/Zi(shared PDB locks kill cache hits). - Exclude cache & build dirs from Windows Defender on self-hosted runners: Add
FASTCI_CACHE_DIRandbuild/to Defender exclusions to avoid real-time scanning on every restored.obj. - Use
fastci wrap+CMAKE_*_LINKER_LAUNCHER: Caching final static libs and binaries avoids re-linking unchanged executables on macOS and Windows. - Use
FASTCI_PP_CACHE=1on Windows: Caches preprocessed output in direct-mode misses to eliminate redundantcl.exe /Pinvocations. - Warm a shared Remote CAS on
main: Let branch pushes populate the remote cache while PRs read from it withFASTCI_REMOTE_READ_ONLY=1.
7. Profile & Optimize with Chrome Trace
Stop guessing where build time goes. Export a Chrome Trace Event file and structured JSON report on every CI run:
fastci run -f fastci.json --trace trace.json --report report.json
fastci stats
Open trace.json in ui.perfetto.dev or chrome://tracing to spot:
- Long tail jobs: One unsplit job holding up the entire build after other cores go idle.
- Unexpected cache misses: Compare
fastci planandfastci hash <file>between two runs to find the exact mutating input. - Scheduler stalls: Check whether
mem_mborcpu_slotsover-reserved the runner's capacity.