Sub topic 9
Counting the cost of artifacts and checkout
This chapter assumes you can read a workflow file, know what needs does, and have seen per-step timings in the Actions UI. Once you split work across parallel jobs, each new job pays fixed costs that a single job pays only once. Two of the largest are checking out the repository and moving files between jobs as artifacts. This chapter shows how to measure both before you decide a split is worth it.
Why splitting is not free
Every job runs on a fresh runner. It starts with an empty workspace, so each job has to do the following:
- Check out the code.
- Restore or install dependencies.
- Download any files produced by earlier jobs.
If a job's real work takes 20 seconds and its setup takes 40 seconds, splitting it further makes the workflow slower to run and more expensive in runner minutes. The critical path may get no shorter either, because all the setup now sits on it.
Measuring checkout
The actions/checkout step appears in the job's step list with its own duration. Open a run, click a job, and read the time beside "Run actions/checkout@v4". For a small repository this is usually a second or two. It grows with repository size and history.
By default, checkout fetches only the single commit being built (fetch-depth: 1). Setting fetch-depth: 0 downloads the full history, which can add a lot of time on a large repository. Use it only when a step needs history, such as a tool that computes changelogs or compares against a base branch.
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1If checkout is slow even with a shallow fetch, look at what the repository contains. Large binary files, many submodules, or Git LFS objects all add transfer time. Options include submodules: false when you don't need them, lfs: false, and sparse-checkout to fetch only the directories a job uses.
Measuring artifacts
Artifacts are files that one job uploads with actions/upload-artifact and another downloads with actions/download-artifact. Both actions show up as steps, so you can time them the same way as any other step.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
- run: ls -RUpload time depends on the number and size of files. A directory with tens of thousands of small files, such as node_modules, is much slower to upload than one compressed archive of the same size. Upload only what the next job needs. If the artifact is large, check whether the downstream job can rebuild it faster than it can download it.
Deciding whether a split pays off
Compare the overhead per job with the time you save. A rough check uses numbers from the UI:
| Measurement | Example value |
|---|---|
| Checkout plus dependency setup per job | 45 s |
| Artifact upload plus download | 30 s |
| Test time in one job | 240 s |
| Test time per job with 4 shards | 60 s |
With four shards, each job takes about 45 + 60 = 105 seconds, so the critical path drops from about 285 seconds to about 105 seconds. That is a clear gain. With a 40-second test job split in two, you would save 20 seconds of test time and spend 45 seconds on extra setup, a net loss.
Total runner time also rises with every split: four shards pay the 45-second setup four times. Check that cost if your plan bills by the minute.
Practical checklist
- Time the checkout, upload and download steps in a recent run.
- Keep
fetch-depthat 1 unless a step needs history. - Upload compressed or minimal output, not whole dependency folders.
- Set a short
retention-daysfor temporary artifacts. - Recompute the critical path after any split, including setup time.
Exercise
A test job takes 90 seconds. Checkout and dependency setup take 35 seconds per job. You consider splitting the tests into 3 shards, which would add 10 seconds of artifact download to each job. What is the approximate duration of each shard job, and does the split shorten the critical path?
Show answer
Each shard runs about 30 seconds of tests (90 / 3), plus 35 seconds of setup and 10 seconds of download, so about 75 seconds. The unsplit job takes 90 + 35 = 125 seconds if it also needs setup, or 90 seconds if you ignore the setup that it pays once. Against 125 seconds the split is faster, so the critical path shortens by about 50 seconds. Total runner time rises from 125 to about 225 seconds.