# How to speed up GitHub Actions Most slow workflows spend their time reinstalling dependencies, running work they did not need, and waiting on a cold machine. Measure first. Open a slow run, expand each step and note its time. Then fix the largest step. The changes below are ordered by how much they usually save for the effort, and each one works on GitHub's own runners. **On Runtime (withruntime.com), a GitHub Actions job runs on a Linux microVM of its own when you change one line of the workflow: `runs-on: runtime`.** Each job's machine has git, Docker, Node, Bun and Python, and is billed by the second at $0.001 a vCPU-minute with 4 GiB of memory per vCPU included. On Runtime's CI/CD, which starts each check from a warm machine, our own repository's pull request checks, 245 test files, went from 4:48 to 7:30 to 2:29, measured 18 Oct 2026. ## 1. Cache dependencies A fresh runner downloads every package on every run. GitHub's `setup-*` actions cache the package manager's download folder when you ask: ```yaml - uses: actions/setup-node@v4 with: node-version: 22 cache: npm # also yarn or pnpm; setup-python takes pip, pipenv or poetry - run: npm ci ``` For anything else, `actions/cache` saves a folder under a key. Make the key the hash of the lockfile, so a changed lockfile builds a new cache and an unchanged one restores the old: ```yaml - uses: actions/cache@v4 with: path: ~/.cache/my-tool key: my-tool-${{ runner.os }}-${{ hashFiles('**/lockfile') }} restore-keys: my-tool-${{ runner.os }}- ``` A repository's caches share 10 GB by default, and GitHub removes an entry that nobody read for 7 days. A cache that is evicted often saves nothing: cache the download folder, which changes rarely, rather than a build folder that changes on every commit. ## 2. Stop runs that no longer matter Each push to a pull request starts a new run, and the old one keeps going. A `concurrency` group cancels it: ```yaml concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true ``` Leave `cancel-in-progress` off for the default branch if every commit there must be checked. ## 3. Run only what changed A `paths` filter skips a workflow when a push touches none of its files: ```yaml on: pull_request: paths: ["api/**", "package-lock.json"] ``` A required check that is skipped this way blocks the merge. Make a filtered workflow required only if it always runs, or check the paths inside the job and exit early. ## 4. Split the work across jobs Jobs run at the same time, steps one after another. Put lint, type checks and tests in separate jobs, and shard a long test suite with a matrix: ```yaml jobs: test: runs-on: ubuntu-latest strategy: matrix: shard: [1, 2, 3, 4] steps: - uses: actions/checkout@v4 - run: npx vitest --shard=${{ matrix.shard }}/4 ``` Each job pays for its own setup: checkout, install and start. Splitting helps when that setup is short beside the work, which is the case once dependencies are cached. ## 5. Use a bigger or warmer machine When the steps are already lean, the machine sets the time. Two things differ between runners: - **Size.** A compiler, a bundler or a parallel test runner finishes sooner with more vCPUs. A run that uses one core gains nothing from more. - **Start.** A cold machine pulls its image and caches before the first step. A runner service that keeps machines ready starts your job without that wait. To move a job to Runtime, connect the repository through Runtime's GitHub App ([CI/CD](/docs/ci)) and change `runs-on`: ```yaml jobs: test: runs-on: runtime-4cpu # was: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci && npm test ``` `runtime` and `runtime-2cpu` are 2 vCPUs, and `runtime-4cpu`, `runtime-8cpu` and `runtime-16cpu` are larger. Labels from other runner services for Linux on x64 also run, on the nearest size. Each job gets a machine of its own that runs that one job and is deleted after, and jobs run only for private repositories. At $0.001 a vCPU-minute, a 4 vCPU job costs $0.004 a minute, billed by the second with no minimum. ## Mistakes to avoid - **Caching `node_modules` instead of the package cache.** It breaks when the Node version or the operating system changes. Cache the download folder and run `npm ci`. - **One job for everything.** A failing lint step should not wait behind a ten-minute test suite. Separate jobs fail fast and show which part broke. - **Scheduled workflows for jobs that are not checks.** A nightly report does not need a repository: a [cron job](/how-to/run-a-cron-job-in-the-cloud) runs it on its own machine at a time you choose, in your time zone. ## Related - [What is a self-hosted runner?](/glossary/self-hosted-runner), the other way to choose the machine a job runs on. - [How to run sandboxes from GitHub Actions](/how-to/run-sandboxes-from-github-actions), for a workflow that needs a machine of its own for one step. - [A test gate for agent-written code](/blog/test-gate-for-agent-written-code), checks for code an agent wrote. - [CI/CD](/docs/ci) in the guides. ## Sources - [GitHub Docs, Dependency caching reference](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching), checked 17 November 2026 - [GitHub Docs, Control the concurrency of workflows and jobs](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency), checked 17 November 2026 Facts on this page were checked on 17 November 2026.