Fixes / 03

Cold caches

Restoring and saving the cache costs more than it should.

What the numbers show

cache steps ≥ 30s or ≥ 10% of the job

A cache that misses, is keyed on a file that changes every commit, or is so large that downloading it takes minutes adds wait instead of removing it. Check the hit rate in the step log before tuning anything else.

The change

Key the cache on the lockfile, with a fallback
- uses: actions/cache@v4  with:    path: ~/.npm    key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}    restore-keys: npm-${{ runner.os }}-
Or use a runner with warm machines
-   runs-on: ubuntu-latest+   runs-on: graphide

Runner options

Options for this case. Judged on setup effort, undo path and sizing. Full comparison
SetupOne line: runs-on: graphide
UndoA pull request restores runs-on
SizingWarm machine sized to the job, up to 32 vCPU
SetupCreate a larger runner, change its label
UndoChange the label back
SizingLarger sizes on paid plans
SetupProvision and patch your own pool
UndoChange the label back, retire machines
SizingWhatever you provision
SetupCheck each vendor's docs
UndoCheck each vendor's docs
SizingCheck each vendor's docs

Verify the verdict stays the same

  1. 01The cache step logs a hit on the second run of the same lockfile.
  2. 02The job's conclusion matches with and without the cache.
  3. 03Clear the cache once and confirm a cold run still passes.