Where CI Time Actually Goes: Duration Attribution by Stage

A pipeline that takes twenty-two minutes is usually described as slow because of the tests. Attribution tells a different story: eight minutes of queue wait behind other jobs, six minutes of dependency installation, four minutes of tests, two minutes of container build, and two minutes of artifacts and reporting. Optimising the tests would save a fraction of what two configuration changes would save.

The short version: measure wall-clock per stage including queue wait, separately from compute time. CI latency is dominated by waiting, and waiting is fixed by concurrency and caching, not by faster test code.

Four time buckets

Every job’s wall clock decomposes into: queue wait before a runner picks it up, setup (checkout, toolchain, dependency install), actual work, and teardown or artifact upload. Most dashboards report only the middle, which is why optimisations target the smallest bucket.

Instrument all four. A pipeline that records scheduled at, runner started, setup finished, work finished, and job ended gives you the decomposition for free, and one afternoon of recording changes the optimisation agenda.

Queue wait is a concurrency problem

Queue wait grows when demand exceeds available runners, usually at the start of the working day and after a merge train begins. Its two levers are concurrency (more runners, or a smaller job matrix) and critical path (fewer jobs that must run before feedback arrives).

Reducing the matrix often beats adding capacity. A test matrix over six versions where two are actually supported burns runners for information nobody acts on. Splitting the pipeline into a fast gate (lint, type-check, unit tests on one version) and an exhaustive nightly is the standard shape: developers get feedback in minutes, thorough coverage still exists.

Dependency installation is usually the largest compute bucket

Package resolution and downloading dominate setup in most projects. The fixes are caching with a key that includes the lockfile hash, using a registry mirror inside the network, and installing only what the job needs. A cache that is keyed on a branch name instead of the lockfile will miss constantly and look like it is working.

Measure the cache hit rate rather than assuming it. A job that reports “cache restored” and still spends four minutes on installation is a cache with the wrong key or a partial cache that only covers the download step.

Tests: parallelise by time, not by count

Splitting tests across runners by file count produces uneven shards, because test durations are not uniform. Splitting by historical duration, with recorded timings from previous runs, produces shards that finish together. On suites with a few long tests, that difference is several minutes per run.

Also look for environmental overhead per test: database setup, fixture loading, and network calls that could be shared. Suites that spend more time setting up than asserting are usually fixable with a session-scoped fixture, and the fix is independent of the test count.

Artifacts, reporting, and the long tail

Uploading coverage, logs, screenshots, and build artifacts can add minutes on slow networks, and it happens at the end when everyone is waiting. Compress, scope, and only upload what a human will actually open. Report generation that parses a large result file synchronously is a common hidden minute.

The long tail is the set of jobs that run after the ones people watch: security scans, license checks, deployment previews. Move them off the critical path entirely, so the feedback the developer waits for does not include work that could run in parallel or later.

A worked example of a twenty-two minute pipeline

On a mid-sized repository, the pipeline records four buckets: queue wait eight minutes at peak, setup six minutes, tests four, and artifacts two. The first change adds two runners and shortens the queue wait to three minutes. The second keys the dependency cache on the lockfile and cuts setup to ninety seconds. The third splits the test matrix from six versions to two on pull requests, with the rest nightly, which halves test time.

The pipeline now runs in about seven minutes at peak, with a fast gate under three. None of the changes touched test code, and none required rewriting the suite, which is where the team had originally planned to spend the quarter. The attribution is what redirected the work.

Two side effects are worth noting. The nightly job now catches version-specific failures a day later than before, which is acceptable for two legacy versions. And the shorter pipeline increased merge frequency, which raised queue pressure again within a month, so the runner count needed one more adjustment. That is the normal pattern: fixing the queue makes the pipeline more attractive to use.

What to check before you commit

  • Record queue wait, setup, work, and teardown as four separate numbers.
  • Report the p50 and p95 wall clock, not the mean.
  • Shrink the test matrix to versions you actually support; add a fast gate.
  • Key caches on the lockfile hash and verify the hit rate.
  • Shard tests by historical duration.
  • Move scans and reports off the critical path.

CI time is mostly a queueing and caching problem wearing a testing costume. Attribution takes an afternoon, and it consistently shows that the minutes everyone complains about are not the minutes that can be saved.

The habit that keeps this from regressing is a review of the pipeline’s p95 duration every month, alongside the four buckets. Without it, new jobs accumulate on the critical path one at a time, each individually reasonable, and the pipeline drifts back to twenty minutes over two quarters. The review takes fifteen minutes and is the only thing that prevents the slow accretion that nobody notices until a release day feels slow again.

Publish the number where developers see it, on the pull request page, rather than in a dashboard nobody opens. A pipeline duration shown next to the merge button changes behaviour far more reliably than a monthly report, because it is visible at the moment someone decides whether to push one more small commit.

And treat the pipeline as a product with a budget: a stated target duration per branch type, reviewed when it is exceeded, rather than an open-ended expectation that it should feel fast. A number makes the trade-offs explicit when someone proposes a new mandatory job, which is what usually erodes the budget in the first place.

Leave a Comment