How to Speed Up a Slow CI Pipeline
A prioritized toolkit for cutting CI time: measure the critical path first, then cache, parallelize, run only what changed, and shrink the work itself.
Key takeaways
- Profile one run to find the critical path, then cache dependencies, cancel superseded runs with a concurrency group, and shard the slowest test job across a matrix.
- Add path filters and build-once artifacts after that.
- Those moves usually take a 20-minute pull request pipeline under 10 minutes without new infrastructure.
On this page
To speed up a slow CI pipeline, time the critical path first, then cache dependencies, cancel superseded runs with concurrency, and shard the slowest test job across a matrix. Add path filters and build-once artifacts next. Bigger runners come last. Those first three moves take about an hour and usually halve a 20-minute pull request pipeline.
Verified against
actions/checkout v7, actions/setup-node v7, actions/upload-artifact v7, actions/download-artifact v8, docker/build-push-action v7, Jest 30.5, Node.js 24 LTS, against docs.github.com (dependency caching, concurrency), jestjs.io CLI docs and the actions release pages. Checked October 2026.
The examples are GitHub Actions, but the ideas port to GitLab, CircleCI or Jenkins with light translation. For more Actions patterns, see the GitHub Actions recipes pillar.
What "fast enough" actually means
Have a target rather than a vague sense that CI is slow. The thresholds we work to:
- Under 10 minutes for the pipeline that gates a pull request. Past this, people stop waiting and context-switch, which is the real cost.
- Under 2 minutes for lint and unit tests, so the first signal arrives while the author is still looking at the change.
- Under 30 minutes for the full main-branch suite, including integration and end-to-end tests a PR run can skip.
At 20 minutes, the fixes below usually get you under 10. At 60, something structural is wrong: a monolithic test suite or a build that starts from scratch every run.
1. Measure the critical path, then guess nothing
Open a recent run and read the job graph: what runs in parallel, what blocks what, and the longest path from start to finish. That path is the only number that sets wall-clock time. Shaving three minutes off a job that already finishes early buys nothing.
Get the numbers from the CLI instead of clicking through logs:
$ gh run list --workflow ci.yml --limit 5
$ gh run view 18812345678 --json jobs \
--jq '.jobs[] | "\(.name)\t\(.startedAt)\t\(.completedAt)"'
Inside the slowest jobs, expand step timings. The culprits are nearly always the same: dependency install, the build, and one bloated test step. Write those down as your baseline.
2. Cache dependencies, and cancel stale runs
If the install step reinstalls the world every run, this is the fastest win available. actions/setup-node caches npm automatically when package.json has a packageManager field (since v6, automatic caching is npm-only), or explicitly with cache: npm. Remember the platform rules: GitHub evicts cache entries not accessed in 7 days, the default limit is 10 GB per repository, and a branch can restore caches from itself, the default branch and (for PRs) the base branch, never from sibling branches.
When someone pushes three times in five minutes, the first two runs are obsolete. A concurrency group cancels them:
# .github/workflows/ci.yml
name: ci
on: [pull_request, push]
concurrency:
group: ci-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npx jest --shard=${{ matrix.shard }}/4
The github.head_ref || github.run_id group is the pattern from GitHub's docs: it cancels superseded pull request runs, while every push to main gets its own group and runs to completion. Our deeper write-ups cover getting cache keys right and which caches pay off.
3. Parallelize the work
Lint, unit tests and type checks rarely depend on each other. Split them into independent jobs and wall-clock cost becomes the slowest one, not the sum.
For a large suite, sharding is the lever. The matrix above runs Jest's --shard=N/4 on four runners; Jest 30.5 requires 1-based indexes and a test sequencer that implements shard (the default one does). Four shards turn a 12-minute test job into roughly three, plus the setup each shard repeats. That overhead is why you do not shard into 50 pieces: past a point, setup dominates and you are burning runner minutes. fail-fast: true stops the remaining shards when one goes red.
4. Run only what changed
The fastest job is the one that never runs. Path filters trigger a workflow only when relevant files change:
# .github/workflows/api.yml
on:
pull_request:
paths:
- "services/api/**"
- "packages/shared/**"
In a monorepo, globs get unwieldy, and affected-package detection earns its keep. Turborepo (turbo run test --filter=...[origin/main]) and Nx (nx affected -t test) build a dependency graph and run tasks only for packages the diff touches and their dependents. Our monorepo CI write-up covers the setup.
5. Build once, reuse everywhere
Build the artifact once and download it in downstream jobs instead of rebuilding in each:
# .github/workflows/ci.yml (jobs section)
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: npm ci && npm run build
- uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
e2e:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- run: npm ci && npm run test:e2e
For container builds, docker/build-push-action@v7 with cache-from: type=gha and cache-to: type=gha,mode=max pulls unchanged layers from the Actions cache instead of rebuilding them. Then be honest about the tests: slow, duplicated integration tests hitting real services are often the biggest line item.
6. Faster runners, last
Hardware is the blunt instrument, so try it after the free wins. Larger GitHub-hosted runners help CPU-bound builds, but you pay a higher per-minute rate, so measure the speedup before committing. For sustained heavy work (native compiles, big image builds, GPU jobs), self-hosted runners keep warm caches on disk; we worked through when that pays in self-hosted runner costs.
The errors you hit along the way
Cache not found for input keys: ...on every run: the key includes something that changes per run (a timestamp,github.sha), or the cache was created on a sibling branch. Key onhashFiles('**/package-lock.json')and letmainpopulate it.- A
Failed to savewarning saying another job may be creating the cache, or that an entry with the same key already exists: several matrix shards tried to save the same key. Harmless; one wins. Canceling since a higher priority waiting request for 'ci-...' exists: the concurrency group is working. If it killsmainruns, your group usesgithub.refinstead ofgithub.head_ref || github.run_id.No tests found, exiting with code 1on one shard: more shards than test files. Reduce the shard count, or pass--passWithNoTests.- A required check stays "Expected" forever: a path-filtered workflow did not run, so branch protection waits for a status that never comes. Use a job-level filter that reports success, or drop that check from required status checks.
Unable to download artifact(s): Artifact not found for name: dist: thenamediffers between upload and download, or the build job was skipped.
Where this breaks
These moves assume the time is in your pipeline. If jobs sit in Queued for minutes, you are short on runner capacity, and caching changes nothing. Sharding also assumes independent tests; a suite with shared database state will flake once split. Path filters are risky when a "shared" change (a lockfile, a base image) should trigger everything, so list those paths explicitly.
Questions people ask
What is the fastest way to speed up GitHub Actions?
Cache dependencies and add a concurrency group with cancel-in-progress: true. Caching often turns a multi-minute npm ci into seconds, and cancelling superseded runs frees runners for work someone is waiting on. Both are a few lines of YAML. After that, shard the slowest test job across a matrix; four shards cut a 12-minute job to roughly three minutes plus setup.
How many shards should I split my test suite into?
Start with four and measure. Each shard repeats checkout, setup and install, so once per-shard setup approaches test time, more shards just burn runner minutes. A reasonable rule of thumb: keep each shard's test time at least twice its setup time. Jest, Playwright and pytest-xdist support splitting; Jest's flag is --shard=1/4.
Why does my CI cache never hit?
Usually the key changes every run, or the cache was saved on a branch yours cannot read. GitHub lets a run restore caches from its own branch, the default branch and the PR base branch, not siblings. Entries unused for 7 days are evicted, and the repository limit defaults to 10 GB, so busy repos also lose caches to eviction.
The call we'd make
Profile one real run and find the critical path, because that tells you which of these moves is worth your afternoon. The order that pays fastest: cache dependencies, add the concurrency block, then shard your slowest job. Path filters, artifact reuse and bigger runners come after. Measure again after each change, and stop when the team stops noticing the pipeline.
Sources
Cite this article
Kiril Urbonas (2026). How to Speed Up a Slow CI Pipeline. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/speed-up-ci-pipeline
[How to Speed Up a Slow CI Pipeline](https://www.devopsness.com/blog/speed-up-ci-pipeline) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.