Skip to content
All posts

How to Speed Up GitHub Actions

Why GitHub Actions builds are slow, and what actually fixes it: cache hits, concurrency groups, matrix sharding, and when faster runners pay off.

Tatu Mäkijärvi

How to Speed Up GitHub Actions

Start with the required check that finishes last, then separate its queue time from checkout, installation, compilation and tests. Repeated downloads need a different fix from serial jobs or a saturated CPU. Measure which work is holding up the merge before changing the runner or splitting the suite.

The table below maps the expensive part of a job to the first change to test. The workflow techniques work on GitHub-hosted, self-hosted and managed runners. Avrea-specific examples explain which cache settings or runner labels they need.

If most of the time goes to...Try first
npm/pnpm/pip/Cargo downloadsThe setup-* actions' cache: input, or a registry proxy in the same datacenter
Getting the repo onto the runnerShallow clone, sparse-checkout in a monorepo, or a local Git mirror
Docker buildsLayer ordering first, then an exported layer cache
CompilationA persistent build cache (Bazel, ccache, Gradle, sccache, Turborepo...)
A long test suiteMatrix sharding
Work that stays CPU- or I/O-bound once the caches hitA faster runner
Old runs stacking up after every pushA concurrency group
Jobs that don't touch what changedpaths: filters

Why is GitHub Actions slow?

Runner choice can shorten compilation and tests even before build caches help. In RunsOn’s November 5, 2026 results, Avrea was the fastest four-vCPU x64 runner across the combined Rust, TypeScript and Docker workloads: 6m58s, versus GitHub’s 18m18s. That is 2.63x as fast. The full benchmark results show each workload and provider.

On a private repository ubuntu-latest is 2 vCPUs, 8 GB of RAM and 14 GB of SSD storage; public repos get 4 and 16. GitHub sells larger tiers up to 96 cores, though only to organizations on Team or Enterprise Cloud, and more cores won’t speed up a serial linker.

RunsOn’s CPU test helps explain the hardware difference: at 2 vCPU and 8 GB RAM, Avrea scored 4,503 and GitHub 2,306 on PassMark single-thread, each the median of five runs. RunsOn also sells runners. The build ranking above sums median build-step times with build caches disabled; CPU scores, queueing and runner overhead are separate measurements.

1. Find the job that’s blocking the merge

GitHub’s run view gives you step-level durations. Start with which checks gate the merge: the required checks in your branch protection or ruleset, plus everything they pull in through needs:. Speeding up a check that gates nothing changes your invoice and not your wait.

Why speeding up your slowest job stops helping

Wall clock through a fan-out is the entry gate, plus the slowest job, plus whatever aggregates at the end. Every job beside that slowest one adds nothing to your wait and everything to your bill.

Cut it and you save time until it’s no longer the slowest, at which point the second-slowest job sets the clock and you’re paying for a fix nobody feels. That’s why the work is a band of jobs at the top, not one job. It’s also why runner-minute savings add up across fixes and wall-clock savings don’t: two fixes aimed at the same job stop overlapping the moment something else becomes the constraint.

Sample several runs, then follow the dependency chain leading to the last required check. A short job can finish last because it waits for an expensive needs: dependency. Use job start and finish times to find gaps: workflow creation to the first job can include queueing, while later gaps can come from dependencies, approvals or capacity limits. A difference between workflow duration and job execution time does not identify the cause by itself.

When the job is queued before any step starts

Separate time waiting for a runner from time spent executing commands. A faster compiler does not help a job that has no machine yet. Check the selected labels and runner group, whether matching runners are online, and whether the account or provider has reached its capacity limit.

Then inspect workflow controls: a needs dependency, an environment approval, max-parallel or a concurrency group can prevent an otherwise available runner from receiving the work. Compare several runs before buying larger machines; record when the job became eligible, when it started and when it finished. GitHub’s runner monitoring guide describes how to check self-hosted runner status and logs.

Split the slow job by step, then fix the biggest share

Split the gating job into steps and label each one: checkout, install, build, test, scan, package, setup. Whichever category dominates is the one to fix, and the table at the top says what to try.

A step whose mean sits well above its median is fine most days and awful on a few, so size it on the bad ones.

Durations tell you where the time went, not why it went there. Avrea records CPU, memory and network per step, so a step that doubled shows up as pegged CPU, memory pressure or a slow download, which is the difference between buying a bigger runner and fixing a cache. When that isn’t enough, SSH into the job while it’s still running:

avr job ssh <job-id>

You land in the working directory as the user the workflow runs as, with the toolchains, environment and caches in place, so you can re-run the failing command instead of adding an echo and pushing again. To catch a job that already failed, hold the VM open with a sleep step under if: failure().

Timing a Gradle build with and without caching

Use the same revision, JDK and Gradle options when comparing runners with the same vCPU count. On a fresh runner and checkout, time the build with caching explicitly disabled.

time ./gradlew assemble --no-build-cache --console=verbose

--no-build-cache overrides org.gradle.caching=true in gradle.properties, so a project setting cannot turn this baseline into a cache hit.

For the cached run, configure a shared remote build cache with writes enabled. Avrea runners preconfigure the Gradle endpoint. Run ./gradlew assemble --build-cache once to populate it, then time the same build on another fresh runner without restoring a local Gradle cache.

time ./gradlew assemble --build-cache --console=verbose

Verbose console output shows task names and outcomes. Look for FROM-CACHE beside tasks whose outputs were reused. Keep volatile commit IDs and timestamps out of otherwise reusable task inputs. If an output needs them, isolate that work in a separate task. The Kafka example workflow uses the project-specific -PcommitId=benchmark setting to hold that input constant.

2. Use faster GitHub Actions runners

For a compatible workflow, testing a managed runner starts with installing the provider and changing runs-on. Check the image, architecture, required tools and network access too. Faster hardware won’t fix repeated work, serial jobs or a cache that isn’t catching anything. For CPU- or I/O-bound work, measure a runner change alongside those workflow fixes.

Hosted, self-hosted, or third-party runners

Self-hosted runners are machines you register with GitHub yourself: you own the image, the patching and the pager. GitHub ships a Kubernetes add-on for running them at scale, Actions Runner Controller (ARC). It starts one runner pod per job and grows or shrinks the pool with demand. This is the answer when the runner has to sit inside your own VPC. The longer version of this comparison, including what each option costs to operate, is in our guide to hosted, self-hosted and third-party GitHub Actions runners.

OptionWhat you operateWhat you controlCost shape
GitHub-hosted, standard or larger tiersWorkflow configurationAvailable runner images and sizesPer minute, billed by GitHub
Third-party providerIntegration, workflow and cache configurationRunner size and cache behaviorProvider usage and plan fees
Self-hosted on Kubernetes (ARC)Cluster, autoscaler, image and patch cycleInstance type, VPC, region, data residencyYour cloud bill plus the engineering time

On Avrea:

# Before
runs-on: ubuntu-latest

# After
runs-on: avrea-ubuntu-latest

avrea-ubuntu-latest is 2 vCPU, matching GitHub’s standard private-repository Linux runner. Avrea uses AMD EPYC 4585PX for Linux x86 and Apple M5 Max for macOS and Linux ARM. Sized labels (avrea-ubuntu-latest-8-vcpu) add cores for work that parallelizes. In our React benchmark on Yarn classic, the build ran 2.1x faster end to end on hardware alone. That is one workload’s result. Job isolation and startup are separate: every Avrea job gets its own VM, and median pickup in the GitHits case study was 16 seconds.

3. GitHub Actions cache: what to cache, and why yours might not be hitting

The GitHub Actions cache (actions/cache) saves a directory under a key you choose and restores it on later runs of the same repository. Cache what gets rebuilt identically every run: package downloads, compiled artifacts, and the caches your own tools write.

Use the caching built into setup-node, setup-python, setup-java and setup-go before you hand-roll keys. On a runner that already proxies the registry locally, that cache: line buys less than it does on GitHub:

- uses: actions/setup-node@v7
  with:
    node-version: 22
    cache: npm   # buys less on a runner that proxies the registry locally
- run: npm ci

It finds the cache directory for your package manager and keys on the lockfile. actions/cache covers what the setup actions don’t, though you wire that up yourself, and on an ephemeral runner anything you didn’t persist is gone when the job ends.

Check where the cache gets written before you debug keys. GitHub scopes entries to the branch that created them, plus the default branch and, for a pull request, its base branch. If only your PR workflow writes the cache, every new PR off main starts cold by design. Save on pushes to your default branch too and PRs have something to inherit.

The cache: input stores the tarballs in ~/.npm, which is worth a lot when the alternative is pulling them across the public internet and worth less when the registry is a proxy one hop away. We haven’t measured where the crossover sits, so time both on your own repo. On Avrea the proxy is on by default and pre-configured for npm, yarn, pnpm, bun, pip, Go modules, Cargo, Maven, Gradle, NuGet, Chocolatey, RubyGems and SwiftPM. uv is the exception: you export UV_INDEX_URL yourself.

Avrea runs four cache layers on the same hardware as the runner. The Actions cache proxy is drop-in compatible: in our testing, a 1 GB restore that averages 73 MB/s and about 14 seconds on GitHub runs at 354 MB/s and under 3 seconds through the colocated proxy. Regular Actions, Git LFS, build and package caches share a 25 GB repository allowance, with additional storage available to purchase. Private Swift package payloads use separate organization storage.

LayerWhat it holdsOn by default
GitHub Actions cacheWhatever actions/cache and the setup-* actions writeYes
Package cacheRegistry downloads for nine ecosystems, through a pull-through proxyYes
Build cacheCompiler and build-tool output for eleven tools: Bazel, ccache, Go, Gradle, Maven, Nix, Nx, sccache, Turborepo, Tuist, XcodePre-configured for Bazel, ccache, Go, Nx, Turborepo and Xcode. Gradle’s remote endpoint is pre-configured, but the build cache must be enabled with --build-cache or org.gradle.caching=true. Maven, Nix and sccache need build or workflow setup; Tuist is opt-in on macOS
Git LFS cacheLarge binaries pulled by actions/checkout with lfs: trueNo, switch it on per org or repo

The bigger reductions in our benchmarks came from avoiding compilation. The Linux kernel build took 27m 23s on GitHub and 24.1s on Avrea with a warm ccache cache. The Next.js and Turborepo build took 3m 23s on GitHub and 1.4s with Avrea’s remote cache warm. These comparisons include different hardware and cache states.

In our Apache Kafka 4.2.0 benchmark, assemble took 5m 44s on GitHub’s runner and 2m 10s on Avrea with the Gradle build cache disabled. Both had 2 vCPUs and ran Temurin 21. With a warm remote cache, tested on Avrea only, the build took 52s.

Tool-native remote caches fetch matching outputs; packing the whole compiler cache into actions/cache also transfers entries the current build may never use.

actions/checkout: getting the repo onto the runner

Clone time costs about the same on every job, so no single run stands out. actions/checkout has defaulted to a shallow, single-commit clone since v2. A job that only posts a notification or calls an API doesn’t need the repo at all. In a monorepo, sparse-checkout narrows the clone to the directories a job touches:

- uses: actions/checkout@v7
  with:
    sparse-checkout: |
      apps/web
      packages/ui

Avrea keeps a mirror of the repository near its runners. Repository-scoped runners prepare the checkout while the VM starts; organization-scoped runners fetch it during the Set up runner step after a job is assigned, which counts toward job runtime. actions/checkout uses the prepared data and can fetch missing data from GitHub. Git checkout acceleration is off until you turn it on:

avr settings set cache.git.enabled true

Set it per organization or per repository. Submodules are a separate switch (cache.git-submodules.mode, with none, top-level and recursive), the first run after you enable it can still fetch from GitHub while the mirror syncs, and it covers Linux and macOS. Windows runners take the normal checkout path.

The caches your tools already write

Your linter, formatter and type checker each ship a work cache, and CI routinely leaves the flag off or points it somewhere the next VM will never see: prettier --cache --cache-strategy content, eslint --cache, tsc --incremental, jest --cacheDirectory=<persisted path>. These store the result of the work, so without them the tool re-parses every file even when the directory restored perfectly.

They also embed absolute paths and stat metadata that differ on a fresh VM, so a common outcome is “Cache restored successfully” followed by the tool scanning thousands of files anyway. Check the tool’s own output, not the cache step’s. Avrea’s build cache covers the compiler and task-runner side of this, Turborepo and Nx tasks included, but not a standalone eslint --cache outside a task graph.

4. Cancel superseded runs with a GitHub Actions concurrency group

For replaceable pull-request checks, canceling an older run can free capacity for the new revision. Keep deployment and merge-queue behavior separate. This example gives non-PR runs their own group so they cannot replace each other:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

The PR number groups revisions of one pull request. The run ID keeps other events separate. Give workflows distinct names because github.workflow is part of the group key.

Setting cancel-in-progress: false alone does not preserve every pending run. GitHub’s default queue keeps one pending run per group and replaces it when another arrives. For a deployment that must serialize multiple pending runs, the current queue: max option allows up to 100 pending runs and cannot be combined with cancel-in-progress: true. Check the queue policy explicitly rather than treating cancellation settings as a durable deployment queue.

Do not rely on a canceled job to publish a warm cache or complete cleanup: actions/cache saves only after a successful job. This example never cancels default-branch runs, which usually seed your caches. Keep required merge_group checks running for the merge queue, and test cancellation separately from ordinary test failures.

5. Shard tests with a GitHub Actions matrix strategy

A matrix creates jobs with different inputs; runner availability and concurrency limits determine how many execute at once. For a test suite the input is a shard number.

Check what a single job already uses first. Jest defaults to CPUs minus one worker, which is one worker on a 2-vCPU runner, and pytest runs serially until you pass -n auto. Whether you’re saturating one machine (--maxWorkers=100%, pytest-xdist, cargo’s --test-threads) also decides whether a bigger runner does anything for you.

strategy:
  matrix:
    shard: [1, 2, 3, 4]
steps:
  - run: npm test -- --shard=${{ matrix.shard }}/4

Keep that denominator in sync with the shard list. strategy.job-total reads it for you, but it counts every job in the matrix, so it only works while shard is the single axis. Add an os: or node: dimension and the denominator becomes the product, shards 1 to 4 run as 1/8 through 4/8, and half the suite silently never runs.

Sharding cuts wall clock. It does not cut runner minutes: every shard pays checkout, toolchain setup, install and cache restore again, so the split floors out at that per-job setup tax. If going from four shards to eight saves almost nothing, you’ve hit it.

Rebalance numbered shards with timing-based splitting (pytest-split). Legs that aren’t fungible, one package each or Postgres against MySQL, have to be split individually. fail-fast also defaults to true, so the first shard to fail cancels its siblings and you get one failure per run to work with.

If shards start in waves, inspect max-parallel, account concurrency, runner availability and upstream job dependencies. The timing alone does not identify which limit you hit.

6. Skip and scope work with paths filters and change detection

paths: filters on the pull_request or push trigger keep a docs-only change from triggering a full test matrix:

on:
  pull_request:
    paths:
      - "src/**"
      - "package.json"
      - "package-lock.json"

A trigger-level paths: filter stops the workflow running at all on a non-matching change, so a required check tied to it never reports and the PR sits blocked forever.

Filter inside the workflow so a final job can report whether the requested work passed or was deliberately skipped. This example is for PR checks on a Node app in apps/web with its own lockfile. Save it as .github/workflows/frontend.yml, and adapt the paths to include all of the app’s shared inputs:

name: Frontend
on: pull_request
permissions:
  contents: read

jobs:
  changes:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
    outputs:
      frontend: ${{ steps.filter.outputs.frontend }}
    steps:
      - uses: dorny/paths-filter@v4
        id: filter
        with:
          filters: |
            frontend:
              - 'apps/web/**'
              - 'packages/**'
              - '.github/workflows/frontend.yml'
  build:
    needs: changes
    if: needs.changes.outputs.frontend == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          cache: npm
          cache-dependency-path: apps/web/package-lock.json
      - run: npm ci && npm test
        working-directory: apps/web
  required:
    if: always()
    needs: [changes, build]
    runs-on: ubuntu-latest
    steps:
      - name: Check the selected work
        env:
          CHANGES_RESULT: ${{ needs.changes.result }}
          FRONTEND_CHANGED: ${{ needs.changes.outputs.frontend }}
          BUILD_RESULT: ${{ needs.build.result }}
        run: |
          test "$CHANGES_RESULT" = success
          if [ "$FRONTEND_CHANGED" = true ]; then
            test "$BUILD_RESULT" = success
          else
            test "$FRONTEND_CHANGED" = false
            test "$BUILD_RESULT" = skipped
          fi

Make the final job the required check for this workflow. It requires successful change detection and either a successful build or an intentional skip. if: always() makes it eligible after an upstream failure; the shell checks stop that failure from becoming a green result. This PR-only example needs an event-appropriate change detector and a merge_group trigger before use with a merge queue. See paths-filter’s supported events and GitHub’s required-check rules.

Put the condition on the job, not the steps. A step-level if: still boots the VM before every step no-ops, six times over on a six-way matrix.

If you skip work on draft PRs with if: github.event.pull_request.draft == false, include ready_for_review in the workflow’s pull_request.types. The default event types do not include that transition. Without it, marking the same revision ready does not rerun the work skipped while it was a draft.

Review which checks must gate every revision. A check run only when a PR opens does not validate later commits, and a required check missing on the current revision can block merging. Move a check to a post-merge tier only when your team accepts that failures will be found after the merge.

Only run what changed, and the four ways it breaks

Scoping the build and tests to the diff is the biggest lever here. Resolve the base commit from whichever event fired, and fall back to a full run when there isn’t one:

env:
  BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
steps:
  - uses: actions/checkout@v7
    with:
      fetch-depth: 0
      filter: blob:none
  - run: |
      if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ] \
         || ! git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then
        echo "no usable base, building everything"
        turbo run build test
      else
        turbo run build test --filter="...[$BASE_SHA]"
      fi

nx affected -t build test --base=$BASE_SHA and vitest --changed $BASE_SHA take the same input. Reach for github.base_ref and your merge-queue and post-merge runs scope to nothing, because it’s only set on pull_request and pull_request_target events.

Four things break, all of them quietly:

  • The dependency graph misses an edge: an undeclared dependency, a runtime import, a generated file.
  • Coverage drops and nobody notices.
  • You test source that was never built, while production ships dist/.
  • A scoper that resolves to “nothing affected” still exits 0, so a broken import reads as a green check.

Turbo and Nx at least fail loudly on an unresolvable base. vitest --changed with passWithNoTests on exits green having run nothing.

The base commit also has to exist in the clone. fetch-depth: 0 with filter: blob:none gets you the commit graph without the file contents, and you pay that back on demand in later commands that need blobs. If your tooling only needs the one commit, git fetch --depth=1 origin $BASE_SHA on top of the default shallow checkout is cheaper. Run scoped and full side by side for a week of PR traffic before you cut over. A speedup that runs fewer tests is indistinguishable from a real speedup until a bug ships.

7. Speed up Docker builds in GitHub Actions

Docker layers that rebuild every time usually come down to build order. The layer cache invalidates from the first changed instruction onward, so a COPY . . above the dependency install rebuilds everything below it whenever any source file changes:

COPY package-lock.json package.json ./
RUN --mount=type=cache,target=/root/.npm npm ci
COPY . .

That cache mount helps inside a single build. It doesn’t travel with cache-to, it lives in the builder’s local state, so on an ephemeral runner it starts empty every run. The layer cache does survive, but only if you export it:

- uses: docker/setup-buildx-action@v4
- uses: docker/build-push-action@v7
  with:
    context: .
    cache-from: type=gha
    cache-to: type=gha,mode=max

mode=max keeps the intermediate stages of a multi-stage Dockerfile; the default keeps only the layers in the final image. scope=backend and scope=frontend give two Dockerfiles in one repo separate entries. On Avrea, add url_v2 to both lines so BuildKit talks to the colocated cache:

    cache-from: type=gha,url_v2=https://cache.avrea.com/
    cache-to: type=gha,url_v2=https://cache.avrea.com/,mode=max

That parameter isn’t optional there. Without it, Linux amd64 builds fall back to the slow upstream path and Linux ARM builds fail. The Docker layer caching docs cover the rest.

Add .git to your .dockerignore. Git metadata changes on every commit, so a COPY . . that sweeps it in invalidates the layer even when no source file moved.

Measure cache import and export alongside the build.

A sleep 10 waiting for Postgres costs ten seconds on every run. Give the services: block health options (--health-cmd pg_isready) and the runner holds your steps until the container answers.

8. Stop CI time from creeping back

CI time creeps back one commit at a time. Someone adds a dependency without pinning it. A setup step in three concurrent jobs gets more expensive in all three at once. Nothing surfaces until the build is slow again and git blame points nowhere useful.

When the same step runs in several jobs at once, make it cheap in every one. Consolidating it into a single upstream job the others wait on turns parallel work into a serial stage.

Watch the keys themselves. A github.sha or github.run_id in a cache key writes a fresh entry every run and, with no restore-keys prefix behind it, reads none of them. Anything in a cache key that doesn’t change the output is a scheduled cache wipe.

Flake belongs on the same list. A first-pass failure rate of f inflates effective time to green by roughly 1/(1-f) on the runs it hits, so 15% is about 1.2x, and it never shows in a duration chart because failed runs get filtered out. Effective wait is worse than that ratio, because the re-run waits for someone to notice the failure. Avrea tracks it directly: flake rate counts jobs that failed where the same step passed on other runs, over a rolling 30 days, with p50 and p95 durations beside it.

Before you delete a step, read the file’s history. A check that looks redundant may enforce a correctness gate or a privilege boundary. Avrea AI, available by request during beta, uses build and test results to propose workflow improvements. Review any proposed change against the checks and permissions the workflow must preserve.

How much can you speed up GitHub Actions?

Measure two outcomes separately: how long developers wait for required checks, and how many runner minutes the workflow consumes. A change can improve one while increasing the other:

ChangeWhat it cutsWhat it depends onEffort
Faster runner hardwareBothWhether what's left is CPU/IO-boundProvider setup and a compatible runner label; self-hosting adds fleet operations
Persistent build and dependency cachingBothHow cacheable the workload isTool configuration; storage or service charges may apply
Canceling superseded runsRunner minutesHow often a second push lands mid-runFree
Skipping and scoping unchanged workBoth, if the job was on the critical pathHow much of your CI is redundantFree, scoping needs a rollout
Matrix shardingDeveloper wait, at the cost of runner minutesHow evenly the suite splitsFree, some refactoring

Re-measure after each change on the job that controls feedback time. To compare runners, use a build or test job with deployment and publication steps disabled. Keep the revision fixed and compare empty-cache runs separately from confirmed cache-hit runs. Avrea’s pricing includes a shared monthly credit equivalent to 3,000 minutes on the 2-vCPU Linux x86 runner; other metered usage draws from the same credit.

Frequently asked questions

Why are my GitHub Actions builds so slow? Check queueing and the dependency chain before execution time. Within the last required check, compare checkout, dependency installation, compilation and tests. Repeated downloads, cache misses, serialized jobs and CPU limits need different fixes; the step timings tell you where to investigate first.

How is Avrea’s cache different from GitHub’s actions/cache? Avrea serves the Actions cache protocol from nearby storage and also provides package proxies and tool-native build caches. Git checkout acceleration and Git LFS caching are separate integrations. Some features are automatic; others need a repository setting or tool configuration. Use the cache setup guide for the tools your job runs.

How do I speed up GitHub Actions without changing runners? Cancel superseded PR checks, cache dependency downloads and build outputs, shard a long test suite or skip jobs whose inputs did not change. Choose the technique that removes work from your required-check path, and verify that required checks still report correctly after failures and skips.

Do third-party runners use up my GitHub Actions free minutes? GitHub currently charges no Actions compute fee for self-hosted or third-party runners, so those jobs do not draw down its included compute allowance. You pay your infrastructure or runner provider instead. GitHub artifact and storage charges can still apply; see the pricing guide.

Last updated

Start shipping with Avrea