Your continuous integration pipeline used to take eight minutes. Now it takes twenty five. Developers push a change, switch to something else, and check back later to see whether the build passed. By the time they see a failure, they have lost the thread of what they were doing. Merges pile up. Releases slip. Someone suggests buying a faster build server, as if the hardware were the problem.
The hardware is rarely the problem. The tests are the problem. More specifically, the number of tests, the way they run, and the ones that fail for no reason. A slow pipeline is usually a test suite that grew without anyone managing it, and the fix is not a bigger machine. The fix is to look at what the tests are actually doing.
Find out where the time goes
Before you change anything, measure. Most CI systems can show how long each step takes. Look at the breakdown. How much time is setup? How much time is the build? How much time is the test run? If the test run is eighty percent of the total, that is where the work is.
Then break the test run down further. Which test files take the longest? Which individual tests are the slowest? Most test frameworks can report timing per test. Run the suite with timing enabled and look at the top twenty slowest tests. You will usually find a small number of tests consuming a large share of the total time.
Ask why each slow test is slow. The common causes are easy to spot once you look. A test that waits for a fixed timeout instead of waiting for a condition. A test that creates a full database, loads a large dataset, and tears it down, when it only needed one row. A test that calls a real external service instead of a fake. A test that sleeps for five seconds to let something settle. Each of these is a small fix, and together they add up to minutes.
There is a useful rule here. A single test should run in under a second. A test file should run in under a minute. A full suite should run in under ten minutes. Those are not strict limits, but they are a good sense of what a healthy suite looks like. If your numbers are far above that, the suite has a problem, and the problem is worth fixing.
Separate the fast tests from the slow ones
Not all tests need to run on every change. Unit tests, which check a small piece of logic in isolation, are fast and should run on every push. Integration tests, which check how pieces work together, are slower and can run less often. End to end tests, which drive the whole application through a browser, are the slowest and should run the least often.
The mistake is to run all three kinds together, on every change, in a single job. That means a developer who changed a single function waits for the browser tests to spin up, log in, and click through the application. That wait adds nothing to the confidence in the change, and it costs minutes every time.
Split the pipeline into stages. The fast unit tests run first, on every push, and they gate the merge. If they fail, the developer knows in a minute or two. The integration tests run next, either on the same push or on a schedule. The end to end tests run last, perhaps only on the main branch or before a release. Each stage gives feedback at the right speed for the change it is checking.
This also changes how developers work. When the fast tests run in two minutes, developers run them before they push, and they fix failures immediately. When the full suite takes twenty five minutes, developers push and hope, and the feedback arrives too late to be useful.
Kill the flaky tests, or quarantine them
Every slow pipeline has flaky tests. A flaky test is one that sometimes passes and sometimes fails, with no change to the code. It fails because of timing, because of shared state, because of a test that depends on another test running first, or because of a resource that is sometimes slow.
Flaky tests are poison for a pipeline. They train developers to ignore failures. When a build fails, the first response becomes rerun it and see if it passes this time. That response is rational, given the history, and it is also dangerous, because it means real failures get rerun and ignored too.
Track flaky tests. When a test fails and passes on retry with no code change, mark it. After three flakes, the test gets fixed or removed. There is no third option. A test that cannot be trusted is worse than no test, because it consumes attention and teaches the team that red builds do not matter.
The fix for most flaky tests is simple. Replace a fixed sleep with a wait for a condition. Give each test its own data instead of sharing state. Run tests in parallel with isolated databases. Mock the external service instead of calling it. These are small changes, and each one removes a source of randomness.
Parallelize, cache, and stop doing work twice
Once the tests are fast and reliable, make the pipeline itself efficient. Run test files in parallel across multiple workers. Most CI systems support this with a single setting. A suite that takes twenty minutes on one worker can take five on four workers, if the tests are independent. If they are not independent, fix the independence problem first, because parallelizing dependent tests just makes the flakes worse.
Cache what does not change. Dependencies, build artifacts, and compiled output can be cached between runs. The first run after a dependency change will be slow. Every run after that should reuse the cache. If your pipeline downloads the same packages on every run, that is free time waiting to be saved.
Stop doing work twice. If the build step compiles the code and the test step compiles it again, that is wasted time. If the lint step runs on every test file and the format check runs the same files again, combine them. Look at the pipeline as a whole and ask whether each step earns its time.
Measure the pipeline like a product
A pipeline that is not measured will get slower without anyone noticing, because the slowdown happens a few seconds at a time. Track the build time every week and write it down. A simple chart, even a spreadsheet, shows the trend. When the line starts climbing, you know something changed, and you can look at what was added that week.
Set a budget for the pipeline the way you would set a budget for anything else. The full suite should finish in under ten minutes. If it crosses that line, fixing it becomes a priority, not a someday task. A budget turns a vague feeling that the pipeline is slow into a specific number that the team can work toward.
Put the build time where everyone can see it. A badge in the repository, a line in the team channel, a number on the dashboard. Visibility creates accountability. When the whole team sees the number creep up, someone will fix it before it becomes a crisis. When the number is invisible, it grows until the day a developer spends an hour waiting for a build and finally complains.
A fast pipeline changes how a team works. Developers merge small changes confidently, because the feedback comes back in minutes. Releases happen more often, because each release is less risky. The pipeline stops being the thing everyone complains about and becomes the thing nobody thinks about, which is exactly what it should be. If yours takes twenty five minutes, the tests are telling you something. Listen to them.