Sub topic 12
Checking that a change made things faster
This chapter assumes you can read run, job and step timings in the Actions UI, know the difference between queue time and execution time, and can run gh commands from a shell. You will compare timings across several runs so you can tell a real improvement from noise.
Why one run proves nothing
A single run before and a single run after a change is weak evidence. Run duration varies for reasons unrelated to your edit:
- Queue time changes with runner availability.
- Cache hits and misses change install and build time.
- Network speed for downloads and checkout varies.
- Test timing varies with the runner's load.
If the "after" run was a cache hit and the "before" run was a miss, you will credit your change for something it did not do. Compare several runs, and compare the same metric for the same job.
Choose the metric first
Pick the number your change should move, and write it down before you measure.
| Change | Metric to compare |
|---|---|
| Dependency caching | Execution time of the install step or job |
| Test sharding | Execution time of the slowest test job, and the run's total time |
| Larger runner | Execution time of the job on the new runner |
| Trigger filters or concurrency | Number of runs started, and total runner minutes |
Execution time is the right metric for most fixes. Queue time is outside your workflow's control, so keep it out of the comparison unless you changed the runner type.
Collect a baseline and a sample after
Collect timings from several recent runs before you merge the change. Then collect the same number of runs after. The first command lists run IDs for a workflow:
gh run list --workflow ci.yml --limit 10 --json databaseId,conclusion,createdAtFor each ID, print the execution time of each job, using the job timestamps from the earlier chapters:
gh run view 1234567890 --json jobs --jq '.jobs[] | {name, seconds: ((.completedAt | fromdateiso8601) - (.startedAt | fromdateiso8601))}'To automate it, loop over the IDs and keep only successful runs:
for id in $(gh run list --workflow ci.yml --limit 10 --status success --json databaseId --jq '.[].databaseId'); do
gh run view "$id" --json jobs --jq '.jobs[] | select(.name == "test") | .name + " " + (((.completedAt | fromdateiso8601) - (.startedAt | fromdateiso8601)) | tostring)'
doneFiltering to successful runs matters. A failed run often stops early and looks fast.
Compare with the median
Averages are pulled around by one slow outlier, such as a cold cache. The median (the middle value when sorted) is steadier. With five runs, sort the numbers and take the third.
Suppose the test job took these seconds:
| Run | Before caching | After caching |
|---|---|---|
| 1 | 212 | 148 |
| 2 | 205 | 141 |
| 3 | 231 | 139 |
| 4 | 208 | 255 |
| 5 | 210 | 144 |
The medians are 210 seconds before and 144 seconds after, a drop of about 31%. Run 4 after the change was a cache miss, and it shows why an average would mislead you here. The averages (213 and 165) would understate the gain.
Check the whole run, not only one job
A faster job does not always shorten the run. The run's duration follows the critical path, the longest chain of jobs linked by needs. If you speed up a job that is not on that chain, the total stays the same.
After a change, check both:
- The job you changed, to confirm the fix worked.
- The run's total duration, to confirm the user-visible wait fell.
If the job improved and the total did not, the critical path runs through a different job. Go back to the timeline and find it.
Common mistakes
- Changing several things at once. You cannot tell which change helped. Make one change per measurement.
- Counting queue time. A busy hour inflates "after" runs and hides a real gain.
- Mixing event types. Pull request runs and scheduled runs behave differently, especially for caches. Compare like with like.
- Ignoring the first run after a cache change. It is usually a miss. Exclude it or note it.
- Trading total cost for speed. Sharding shortens the run but adds runner minutes, because each job repeats checkout and install. Check the cost if it matters to you.
Exercises
Exercise
A test job took 180, 175, 410, 178 and 182 seconds across five runs before a change. After the change, it took 150, 148, 152, 149 and 300 seconds. What are the two medians, and what does the improvement look like?
Show answer
Sorted before: 175, 178, 180, 182, 410, so the median is 180 seconds. Sorted after: 148, 149, 150, 152, 300, so the median is 150 seconds. The job is about 17% faster. The 410 and 300 second runs are outliers, likely cache misses or a slow runner, and the median ignores them.
Exercise
You split tests into four shards and the shard jobs each finish in half the old time, but the run's total duration barely changed. Name two likely causes.
Show answer
The critical path may run through another job, such as a long build or deploy job linked by needs. Queue time for the four parallel jobs may also have grown, because they need four runners at once. Check the job timeline for both.