How to Batch Matrix Jobs in CI
A wide matrix multiplies per-job overhead. Batch combinations so you pay setup cost fewer times.
Every matrix leg has fixed overhead: provision, checkout, install. A huge matrix pays that tax N times. Batching trims N.
Prune with include/exclude
You rarely need every OS x version x flag combination. exclude removes redundant legs; include adds only the specific combos you care about.
Batch versions inside one job
Instead of one job per minor version, test a representative set in a single job loop to amortize setup overhead.
.github/workflows/ci.yml
strategy:
matrix:
node: [18, 20, 22]
exclude:
- { node: 18, os: macos-latest }Full matrix off the hot path
Run a slim matrix on PRs and the full matrix on main or nightly so day-to-day CI stays fast and cheap.
Key takeaways
- Every matrix leg pays fixed setup overhead.
- Prune with include/exclude; batch where you can.
- Reserve the full matrix for main/nightly.
Related guides
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
How to Cut macOS CI MinutesReduce expensive macOS GitHub Actions minutes: move non-Apple work to Linux, cache aggressively, and reserve…
How to Reduce Windows CI CostLower Windows GitHub Actions cost: move cross-platform jobs to Linux, cache and speed up slow Windows steps,…
How to Fail Fast to Save CI MinutesOrder CI to fail fast: run cheap checks first, enable matrix fail-fast, and stop a doomed pipeline early so y…