---
title: "How to speed up Rust CI"
description: "Speed up Rust CI with the right linker, sccache or rust-cache, a lean CI build profile, cargo-nextest partitioning, and fast lint jobs."
url: https://9apes.com/blog/speed-up-rust-ci/
---

# How to speed up Rust CI

To speed up Rust CI, cache compiled dependencies between runs, turn off incremental compilation and full debug info in CI, link with a fast linker, and run tests with cargo-nextest so they can be split across machines without recompiling. Rust builds are CPU-bound once dependencies are cached, so after those changes the remaining lever is the hardware compiling your crates.

This post is part of a series on [speeding up CI](/blog/speed-up-ci-builds/). The hub covers techniques that apply to every language; this one covers Cargo and the Rust toolchain.

## Cache dependencies, not your workspace

Most of a cold Rust build is compiling dependencies that rarely change. There are two main ways to keep that work across CI runs.

**`Swatinem/rust-cache`** saves `~/.cargo` and the dependency artifacts in `target/` to the GitHub Actions cache. It deliberately leaves out your own workspace crates, since they change on every commit, and prunes stale artifacts:

```yaml
- uses: actions/checkout@v7
- uses: Swatinem/rust-cache@v2
  with:
    save-if: ${{ github.ref == 'refs/heads/main' }}
- run: cargo build --locked
```

Saving only from `main` keeps pull requests from filling the cache with short-lived entries; they still restore from it.

**sccache** caches individual compiler invocations instead of the whole `target/` directory, and can share them across jobs, branches, and machines through the Actions cache or an object store:

```yaml
env:
  SCCACHE_GHA_ENABLED: "true"
  RUSTC_WRAPPER: "sccache"
steps:
  - uses: actions/checkout@v7
  - uses: mozilla-actions/sccache-action@v0.0.11
  - run: cargo build --locked
```

rust-cache is simpler and restores everything in one archive. sccache is more granular and shares better across jobs with different feature sets, but it [cannot cache](https://github.com/mozilla/sccache) incrementally compiled crates or crates that invoke the linker (`bin`, `dylib`, `cdylib`, `proc-macro`). Try rust-cache first; reach for sccache when many jobs build overlapping crate graphs.

Either way, measure restore time against compile time. A multi-gigabyte `target/` archive can take longer to download and extract than the crates take to build on a fast machine.

## Turn off incremental compilation and full debug info

Incremental compilation helps when you rebuild the same tree locally. In CI, each job usually builds once, so incremental data is just extra disk writes, and sccache cannot cache incremental crates. rust-cache sets `CARGO_INCREMENTAL=0` for you; with sccache, set it yourself.

The `dev` profile also generates full debug info by default, which slows compilation and linking and makes `target/` larger to cache. Unless you debug CI binaries, reduce it in a CI-specific profile:

```toml
# Cargo.toml
[profile.ci]
inherits = "dev"
incremental = false
debug = "line-tables-only"
```

```bash
cargo build --profile ci
cargo nextest run --cargo-profile ci
```

`line-tables-only` keeps file and line numbers in backtraces. Use `debug = 0` if you do not need them at all. The [Cargo profiles reference](https://doc.rust-lang.org/cargo/reference/profiles.html) lists every option.

## Use a faster linker

Linking is single-threaded per binary in older linkers and runs after everything else, so it sits on the critical path of every build and every test binary.

Since [Rust 1.90](https://blog.rust-lang.org/2025/09/18/Rust-1.90.0/) (September 2025), `x86_64-unknown-linux-gnu` links with LLD by default, so many projects already got this improvement for free. Two linkers go further:

- **[mold](https://github.com/rui314/mold)** 3.0, released in October 2026, is a rewrite of mold in Rust and a drop-in replacement for the 2.x line. Its author benchmarks it well ahead of LLD.
- **[wild](https://github.com/wild-linker/wild)** is a newer linker written in Rust that aims for very fast links, with incremental linking planned. It makes no production-readiness claim yet.

To try mold on Linux:

```toml
# .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
```

Link time matters most for workspaces with many test binaries, because every integration test file is its own binary. Measure a full `cargo nextest run` build, not one binary.

## Run tests with cargo-nextest

[cargo-nextest](https://nexte.st/) runs each test in its own process, schedules them across all cores, and reports slow and flaky tests clearly. Its maintainers report up to three times faster test runs than `cargo test`.

Its most useful CI feature is building once and testing in parallel. One job compiles the tests and archives them; a matrix of jobs downloads the archive and runs one partition each, with no compilation:

```yaml
jobs:
  build-tests:
    runs-on: 9apes-8vcpu-ubuntu-2404
    steps:
      - uses: actions/checkout@v7
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with:
          tool: nextest
      - run: cargo nextest archive --workspace --archive-file tests.tar.zst
      - uses: actions/upload-artifact@v7
        with:
          name: nextest-archive
          path: tests.tar.zst

  run-tests:
    needs: build-tests
    runs-on: 9apes
    strategy:
      matrix:
        partition: [1, 2, 3]
    steps:
      - uses: actions/checkout@v7
      - uses: taiki-e/install-action@v2
        with:
          tool: nextest
      - uses: actions/download-artifact@v8
        with:
          name: nextest-archive
      - run: |
          cargo nextest run --archive-file tests.tar.zst \
            --partition slice:${{ matrix.partition }}/3
```

The archive does not include source, so check out the same commit in every test job. `slice:` partitioning is the recommended mode; the older `count:` mode is [deprecated](https://nexte.st/docs/ci-features/partitioning/).

This also lets you size each job separately: a larger runner for compilation, which uses every core, and smaller runners for test partitions.

## Keep lint jobs on check, not build

`cargo check` and `cargo clippy` stop before code generation, which is the slowest part of a build. Formatting needs no compilation at all. Run them as their own fast job:

```yaml
- run: cargo fmt --all --check
- run: cargo clippy --workspace --all-targets --locked -- -D warnings
```

Give this job its own cache key (rust-cache's `shared-key` or a separate job name), since check artifacts are not the same as build artifacts.

## Speed up Docker builds of Rust services

A Dockerfile that runs `COPY . .` and then `cargo build` recompiles every dependency whenever any source file changes. [cargo-chef](https://github.com/LukeMathWalker/cargo-chef) computes a recipe from your manifests so dependencies build in their own cached layer:

```dockerfile
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release
```

That layer is only useful if your CI keeps Docker layers between runs. The [Docker layer caching guide](/blog/docker-layer-caching-github-actions/) covers that part, with measurements.

## Large workspaces: unify features

In a workspace, the same dependency can be compiled several times with different feature sets, depending on which crates you build. [cargo-hakari](https://docs.rs/cargo-hakari/latest/cargo_hakari/) maintains a "workspace-hack" crate that forces one unified feature set, so each dependency builds once. It pays off in workspaces with dozens of crates; for small projects it is unnecessary.

## What is still nightly

Two compiler changes promise large speedups but are not available on stable Rust yet:

- The **Cranelift codegen backend** generates code faster than LLVM for debug builds. It is [nightly-only](https://github.com/rust-lang/rustc_codegen_cranelift) and has gaps, such as partial SIMD support.
- The **parallel frontend** (`-Z threads`) parallelizes parts of compilation that are serial today. It is an [active project goal](https://goals.rust-lang.org/2026/parallel-front-end.html) without a stabilization date.

Neither belongs in a required CI job on a stable toolchain yet. They are worth watching because both change how much a build benefits from extra cores.

## How 9apes speeds up Rust CI

After caching, Rust CI is compilation and linking, and both are CPU-bound. That makes Rust one of the ecosystems where the runner changes results the most.

9apes runs each GitHub Actions job in a fresh microVM on hardware chosen for high single-core performance with NVMe storage. Fast cores shorten serial phases such as linking and the last crates in the dependency graph; NVMe helps with the heavy disk writes of `target/`. Sizes go up to 8 vCPU on Linux x86_64, so you can give compile jobs more cores and keep test partitions small.

The [9apes benchmarks](/benchmarks/) include a cold build of [`PeerDB-io/peerdb`](https://github.com/PeerDB-io/peerdb), which compiles Rust with cargo and Go. On August 27, 2026, the timed build step took a median of 1,283 seconds on GitHub-hosted 2 vCPU runners and 492 seconds on 9apes 2 vCPU runners, across three runs each with dependency caching disabled. That measures a cold build of one project, not your pipeline or a warm cache.

To measure your own, follow the [quick start](/docs/quick-start/) and change the runner label on your build job:

```diff
- runs-on: ubuntu-latest
+ runs-on: 9apes-8vcpu-ubuntu-2404
```

Keep the cache configuration identical and compare complete job time and [cost](/pricing/) over several runs.

## Should I use sccache or rust-cache in GitHub Actions?

Start with rust-cache: it is one step and covers most projects. Use sccache when many jobs compile overlapping dependencies with different features or targets, or when you want a cache shared beyond the Actions cache.

## Do I still need to configure LLD for Rust?

Not on `x86_64-unknown-linux-gnu` with Rust 1.90 or later, where LLD is the default. You can still try mold or wild for faster links.

## Why set CARGO_INCREMENTAL=0 in CI?

CI usually builds each tree once, so incremental data only adds disk writes. sccache also cannot cache incrementally compiled crates.

## Does a bigger runner make Rust builds faster?

Usually, up to the parallelism of your crate graph. Linking and the final crates are serial, so single-core speed matters as much as core count. Measure at several sizes.
