Skip to content

How to Reduce Build Times and Why It Matters

Our 14-minute build was costing us 28% of PR throughput. Here's the exact sequence of optimizations that cut it to 90 seconds.

7 min read
A compact parallel assembly line building circuit modules.
On this page

Our build took 14 minutes. Nobody complained because it had always been 14 minutes. We treated it like weather. Just something you deal with.

Then we cut it to 90 seconds and everything changed.

PR throughput went up 28%. Developers stopped batching changes into massive PRs (because the feedback loop was fast enough to ship small ones). Code review quality improved because PRs were smaller. The flaky test rate dropped because developers could actually re-run tests without losing their afternoon.

All from fixing something nobody thought was a problem.

The Hidden Cost of Slow Builds

Build time isn't just "time waiting." It's a chain reaction of behavioral changes that compound into massive productivity loss.

Context switching. When a build takes more than about 90 seconds, developers switch to something else. Slack, email, Twitter, another task. Research on interrupted programming examines the work needed to resume a task. It does not justify adding a fixed 15-25 minutes to every build. Measure waiting and resumption in the workflow you are changing.[1]

PR bloat. When builds are slow, developers batch changes to avoid triggering the pipeline repeatedly. Instead of three focused PRs, they submit one monster PR with 800 lines changed. Reviewers skim instead of reading. Bugs sneak through. Merge conflicts multiply.

Reduced experimentation. Fast builds encourage experimentation. "Let me try this approach and see if it works." Slow builds discourage it. "I'll just go with the first approach because I don't want to wait another 14 minutes to validate the alternative." Over time, this leads to worse technical decisions.

Flaky test tolerance. When re-running tests is cheap (30 seconds), developers investigate failures immediately. When re-running tests costs 14 minutes, they hit retry and hope. Flaky tests accumulate. Trust in the test suite erodes. Eventually, developers stop writing tests because they view the suite as unreliable.

Measuring What Matters

Cold build Clean state Incremental build One file changed Test duration Separate test lanes
Figure 1. Compare the same build conditions before and after an optimisation.

Before optimizing, measure. You need three numbers:

  1. Cold build time: From clean state to running application. This is what new branches and CI experience.
  2. Incremental build time: After changing one file. This is what active development feels like.
  3. Test suite duration: Unit tests, integration tests, and e2e tests separately.

I use this classification:

Build Type Good Acceptable Problem
Incremental < 2s 2-10s > 10s
Cold < 30s 30s-3min > 3min
Unit tests < 30s 30s-3min > 3min
Integration < 3min 3-8min > 8min
Full CI < 5min 5-15min > 15min

If any of your numbers fall in the "Problem" column, you're losing significant productivity.

The Playbook: From 14 Minutes to 90 Seconds

Caching Skip unchanged work Parallel tests Shards Incremental tsc Reuse project graph Docker layers Reuse dependencies
Figure 2. Choose an optimisation after identifying which work the run repeats.

Here's the exact sequence of optimizations we applied. Each one is independent, but they compound.

1. Add Build Caching (Savings: 40-60%)

This is the single biggest win for most projects. Tools like Turborepo, Nx, or Gradle's build cache store the results of previous builds and skip unchanged work.[2]

For a TypeScript monorepo, Turborepo's remote cache was transformative:

json
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**"]
    },
    "test": {
      "dependsOn": ["build"],
      "outputs": ["coverage/**"]
    }
  }
}

When developer A builds package X and pushes the cache, developer B skips that build entirely. In a monorepo with 20+ packages, most builds become cache hits. Our cold build went from 14 minutes to 6 minutes just from this.

2. Parallelize Test Execution (Savings: 30-50%)

Test runners can execute files or tests in parallel already. For suites that benefit from additional CI workers, split the files across shards:[3]

yaml
# GitHub Actions example
test:
  runs-on: ubuntu-latest
  strategy:
    matrix:
      shard: [1, 2, 3, 4]
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: 22
        cache: npm
    - run: npm ci
    - run: npx vitest run --shard=${{ matrix.shard }}/4

Four parallel shards cut our test time from 8 minutes to 2.5 minutes. The wall-clock time is bounded by the slowest shard, so balance your test distribution.

3. Use Incremental TypeScript Compilation

If you're running tsc on every build, you're recompiling unchanged files. Enable incremental mode:[4]

json
{
  "compilerOptions": {
    "incremental": true,
    "tsBuildInfoFile": "./.tsbuildinfo"
  }
}

This alone cut our type-checking step from 45 seconds to 3 seconds for typical changes.

4. Optimize Docker Builds with Layer Caching

Docker builds are often slow because they invalidate the cache unnecessarily. Order your Dockerfile from least-changing to most-changing:[5]

dockerfile
# Good: dependencies change less often than source code
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

Use BuildKit's cache mounts for package managers:

dockerfile
RUN --mount=type=cache,target=/root/.npm npm ci

5. Replace Heavy Tools with Faster Alternatives

Sometimes the biggest win is swapping tools:

  • Jest to Vitest: Benchmark the actual suite, including startup, transforms and test environment setup. Migration effort and speed depend on the project.
  • Webpack to Vite/Turbopack: Modern bundlers are dramatically faster for development builds.
  • ESLint to Biome: Compare the rules and framework support you need before trying a timed run. Tooling changes also have compatibility and configuration costs.

We replaced Jest with Vitest and our unit test suite dropped from 90 seconds to 18 seconds. No test changes required.

The Contrarian Take: Don't Optimize the Wrong Build

I see teams obsess over CI build times while ignoring local development speed. That's backwards. Developers run local builds 10-50x more often than CI runs. A 30-second improvement in local incremental build time is worth more than a 5-minute improvement in CI.

The priority should be:

  1. Local incremental build (developers feel this hundreds of times per day)
  2. Local test execution (developers run this dozens of times per day)
  3. CI pipeline (developers wait for this a few times per day)
  4. Cold build / environment setup (developers hit this a few times per week)

Optimize in that order. Most teams start at the bottom and work up, which is exactly wrong.

The Stealable Framework: The Build Time Budget

Set a build time budget for your team. Make it explicit and visible. Here's how:

  1. Set targets. Local incremental: under 2 seconds. CI: under 10 minutes. Cold: under 3 minutes.
  2. Monitor weekly. Add build time to your CI and track the p50, p90, and p99 over time.
  3. Create an alert. When the p90 exceeds your target by 20%, file a ticket automatically.
  4. Dedicate capacity. Reserve 10% of sprint capacity for build performance. This isn't overhead. It's investment in every other task moving faster.

The teams that treat build time as a first-class metric are, in my experience, the teams that ship the fastest. Not because fast builds are the most important thing. But because caring about builds means caring about the developer experience. And that mindset permeates everything.

Start measuring. Start caring. The 14-minute build you're tolerating right now is costing you far more than you think.

Frequently asked questions

Which build time should I measure first?

Measure the local incremental build, cold build and test lanes separately. Start with the delay developers encounter most often, then use the same machine, inputs and cache conditions to compare a change.

Does remote caching make every build faster?

Caching helps when work can reuse a valid earlier result. Declare the relevant inputs and outputs correctly and measure cache hits, because changed inputs, missing artifacts or cache overhead can affect the result.

Will adding more test shards divide execution time evenly?

Sharding runs different files on separate workers, and the slowest shard bounds completion time. Include worker setup and shared resources in the measurement and check whether the suite can safely run in parallel.

Should I replace the test runner before profiling?

Inspect where the existing run spends time and try a representative comparison. A migration can require configuration or mock changes, and the result depends on the suite rather than a universal speed multiplier.

Sources

  1. [1]Evaluating Cues for Resuming Interrupted Programming Tasks · Microsoft Research
  2. [2]Configuring turbo.json · Turborepo
  3. [3]Improving Performance · Vitest
  4. [4]TSConfig Option: incremental · TypeScript
  5. [5]Optimize cache usage in builds · Docker Docs

Checked against these sources on

Related Articles