How to Speed Up Slow CI Builds: 9 Fixes That Actually Work
A slow pipeline taxes every pull request. Developers wait, context switches pile up, and a small fix that should take ten minutes eats half the morning. If you want to speed up slow CI builds, start by measuring where the time actually goes, then fix the biggest bottleneck first. The nine fixes below are ordered by the payoff most small teams see, and none of them needs a pipeline rewrite.
Find the bottleneck before you change anything
Open the timing breakdown for a recent run before touching a config file. Most CI systems show how long each job and step took, and the slowest step is usually obvious once you look. A build that spends most of its time installing dependencies has a different fix than one that spends it running tests, and guessing wrong wastes an afternoon. Note the three slowest steps, record the total run time, and keep that number as your baseline so you can tell whether a change helped.
If you have not set up a pipeline yet, or yours grew by accident over a year, it helps to read a clear walkthrough of how to build a CI/CD pipeline with GitHub Actions first, so you know which parts are supposed to do what before you start trimming them.
Cache and install less
Dependency installation is the most common time sink on small projects. A fresh install on every run downloads the same packages again and again, and on a cold runner that alone can take longer than the tests.
1. Cache dependencies between runs
Cache the dependency directory and key it on the lockfile, so the cache is used again until dependencies change. In GitHub Actions, the cache action handles this with a few lines:
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Use the lockfile hash in the key. A key that never changes serves stale packages, and a key that changes on every commit never hits the cache. Check the cache hit rate in the logs after a few runs, and clear a bad cache rather than debugging around it.
2. Install only what each job needs
Many pipelines install full development dependencies for a job that only runs a linter or a build. Split the install per job, and skip optional dependencies where the tool allows it. Use the clean install command for your package manager, such as npm ci for Node.js, which reads the lockfile and skips the resolution step a plain install repeats. If you are setting up a Node.js pipeline from scratch, this guide to building a GitHub Actions pipeline for Node.js shows where the install step belongs and how to keep it lean.
3. Reuse Docker layers instead of rebuilding images
When a job builds a Docker image, each layer rebuilds only if the files it depends on changed. Order the Dockerfile so the slow, stable layers come first: copy the lockfile and install dependencies before copying source code. That way a code change rebuilds only the last layers. Enable the builder cache in CI, and pin the base image to a specific version so an upstream change does not quietly rebuild everything. For self-hosted runners, the setup in how to set up GitLab CI with Docker runners covers the runner side of this in detail.
Run less work, and run it in parallel
The second group of fixes is about doing fewer things per run and doing the rest at the same time. These are often the cheapest wins because they change config, not code.
4. Split the test suite across parallel jobs
A single job running a thousand tests in sequence is an easy target. Split the suite by folder, file, or test runner shard, and run the parts as separate jobs in one workflow. Most test runners support sharding or a simple file list per job. Keep the split even: one shard that takes five times longer than the others sets the pace for the whole run. Start with two or three shards and add more only while the total run time keeps dropping.
5. Skip jobs that do not need to run
Not every change needs every check. A docs-only edit does not need the full test suite, and a change to the frontend does not need backend tests. Use path filters so jobs run only when files they care about changed, and add a docs-only skip where your CI supports it. Review the workflow file once a quarter and delete jobs nobody can explain; pipelines collect checks the way drawers collect cables.
6. Fail fast and put cheap checks first
Run linting and type checks before the heavy test suite, and stop the run on the first failure instead of letting every job finish. A typo that a linter catches in seconds should not cost a ten-minute test run. Turn on fail-fast for matrix jobs too, so a broken build on one version does not keep burning minutes on the others while you wait.
Faster runners, slimmer images, and steady habits
The last three fixes are about the environment the pipeline runs in and the habits that keep it fast over time.
7. Pick the right runner for the job
Default hosted runners are shared and modest, which is fine for linting and small test suites but slow for heavy builds. If builds queue or crawl, try a larger runner size for the heavy jobs only, or a self-hosted runner on a machine you control. Measure the change: a bigger runner helps only if the job was CPU or memory bound, and it costs more, so keep the small runner for the light jobs.
8. Trim the pipeline itself
Check for steps that run twice, checkouts that happen in every job when only one job needs the code, and setup actions pinned to old versions. Each extra step adds startup time and another place to break. Keep the workflow file readable, one job per purpose, and remove steps that duplicate what another job already verified. While you are cleaning up, do not trade speed for safety: keep the checks that protect the pipeline itself, and review the steps to harden a CI/CD pipeline before removing anything that looks like a security check.
9. Track build time and revisit it monthly
CI speed drifts. A new dependency here, an extra test file there, and the pipeline is slow again six months later. Record the average run time once a month, or set a simple alert when runs pass a threshold your team agrees on. When the number creeps up, look at the timing breakdown again and repeat the process: find the slowest step, fix it, measure. Teams that do this stay fast; teams that do not end up scheduling a painful cleanup once a year.
Speed up slow CI builds: what to try first
If you only have an hour, do fixes 1, 4, and 6: cache dependencies, split the tests, and fail fast. On small projects those three usually account for most of the wasted time, and each one is a small config change you can verify in the next run. Then work through the rest in order, measuring after each change so you know which fix earned its keep.
FAQ
How do I speed up slow CI builds without spending more money?
Start with caching, path filters, and parallel test jobs. Those three cost nothing on hosted runners and fix the most common causes of slow builds. Pay for bigger runners only after you have measured that the job is CPU or memory bound.
Will caching make my builds unreliable?
Not if the cache key includes the lockfile hash. The cache is used again only while dependencies are unchanged, and a lockfile change builds a fresh cache. If a run behaves oddly, clear the cache and rerun before debugging anything else.
How often should I review CI build times?
Once a month is enough for most teams. Check the average run time, look at the slowest step, and fix it before it grows into a project of its own.