---
title: "Test sharding in CI"
description: "Why an even split of test files can still leave CI waiting, how measured durations guide the split, and how to verify that the same tests still run."
url: https://mh0pe.github.io/blog/slowest-shard/
author: "Madison Hope Steiner"
published: 2026-11-21
modified: 2026-11-21
---

[← All writing](https://mh0pe.github.io/blog/)

# The slowest shard is the build.

**Follow the last worker** Each letter is one test; its width is estimated duration. Assigning long tests first to the least-loaded worker shortens the longest lane in this example without dropping a test.

Why an even split of test files can leave one worker doing most of the waiting.

[ASH #965: weight test shards by duration](https://github.com/awslabs/automated-security-helper/pull/965)

By [Madison Hope Steiner](https://mh0pe.github.io/about/)

Automated Security Helper Developer tools

**In this article**

The last worker

At a glance

Parallel tests don't finish when the average worker is done. The last worker sets the wait.

A test run can have eight green jobs and still keep you waiting on the ninth. When I worked on test sharding in Automated Security Helper, I wanted to know how much of that wait came from the tests themselves and how much came from the way we divided them. The two problems need different fixes.

The old assignment gave each test module a stable home by hashing its name. That made it easy to reproduce a split and to absorb new modules. But it did not know what a module cost to run. Equal numbers of files looked fair on paper. They could put two slow modules in one worker and a handful of quick ones in another.

## Equal files are not equal work.

I drew the workers as lanes and the tests as blocks. If two long blocks land on the same lane, the empty space in the other lanes does not help. They cannot go back in time and pick up the work. If the test job is a gate, its finish time depends on the heaviest lane, not the mean.

Three workers run at the same time, but the first carries three long tests.

**Equal counts, uneven work.**

Each lane gets three test blocks. One lane still has much more work.

**Diagram key**

**Top lane: Worker 1**
Three long tests set the finish time.

**Lower lanes: Workers 2 and 3**
Their three tests each are shorter.

- [ASH #965: weight test shards by duration](https://github.com/awslabs/automated-security-helper/pull/965)

That changed the question I asked of the planner. It didn't need to predict the next run down to the second. It had to make a better decision about where the expensive work went with the information we already had.

**Measure the wait reviewers actually see.**

1. Look at the last worker to finish
2. Separate test execution from setup
3. Ask which work could have gone elsewhere

A test plan can balance recorded execution time without accounting for runner startup, contention, or variance.

Elapsed time has more than one part as well. [CI latency has more than one clock](https://www.linkedin.com/pulse/ci-latency-has-more-than-one-clock-madison-hope-steiner-cissp-0o3wc/) separates the time a job spends waiting for a runner from the time it spends running.

## Give the heavy work a place first.

In the change I submitted, recorded durations drive a longest-first plan. Start with the largest job, put it on the least loaded lane, and repeat. Smaller pieces can fill the gaps that are left. There was also a case where the module itself was too big to balance as one unit. Splitting that module helped in a way that shuffling it around never could.

The tiles keep their letters as they change which worker runs them.

**Place the long tests first.**

The same blocks move into gentler loads across three workers.

**Same nine test pieces** ** Longest worker lane**

Follow the same blocks, A through I, as they move. Watch the longest lane shrink. The historical replay models scheduled test-seconds, not observed CI wall time or passing tests.

**Diagram key**

**Long labeled tiles: Long blocks**
One moves into each of the three lanes.

**Dashed line: Last worker**
The finish moves earlier in this example.

- [ASH #965: weight test shards by duration](https://github.com/awslabs/automated-security-helper/pull/965)

On historical Python 3.12 Windows integration results, the heaviest lane in the replay went from 4,708 to 1,695 test-seconds. An even share of the recorded work would have been about 1,659. Those are modeled loads, not shorter wall-clock times measured after deployment. A replay tells me the plan is worth trying. A real run tells me whether the saved waiting survived contact with the runners.

A new test cannot wait for a timing record before it is allowed to run. The plan keeps deterministic hash assignment as a fallback for tests it hasn't seen. If the plan is malformed, the tooling rejects it. Missing history and broken configuration get different responses.

ASH's scan side has a placement problem of its own. [Designing a scanner fan-out that can be collected honestly](https://www.linkedin.com/pulse/designing-scanner-fan-out-can-collected-honestly-steiner-cissp-jlzfc/) separates who owns each piece of work from who may announce the result.

## Prove the faster plan kept the tests.

There is a straightforward way to get a faster suite that nobody wants: accidentally stop running part of it. I compared the original collection with the union collected by the new shards. The review records 7,832 integration tests and 61,601 unit tests in that check, with no dropped or duplicated tests. Collection establishes membership, not whether execution will pass.

The new layout holds the same nine test blocks as the opening layout.

**Count what made the move.**

All nine illustrated blocks are still there, once each.

**Diagram key**

**All three lanes: A through I**
The same nine identities appear once each.

**Right of longest lane: Finish line**
An estimate of the load, not a wall-clock measurement.

- [ASH #965: weight test shards by duration](https://github.com/awslabs/automated-security-helper/pull/965)

I would keep the assignment and its proof apart. Show that balancing reduces the modeled peak. Separately show that every test still has exactly one home. If one check fails, you can tell whether you lost the time savings or the meaning of the gate.

If you have already added workers and the suite still feels slow, what does the last worker know about your tests that the scheduler doesn't?

Running shards in parallel also makes the suite [a small concurrent system](https://www.linkedin.com/pulse/test-harness-small-concurrent-system-madison-hope-steiner-cissp-mwl7f/) with deadlines, processes and cleanup of its own, which I wrote about on LinkedIn.

**For a closer technical look**

- Reported seconds are a replay of historical durations, not a post-merge benchmark or isolated Linux result.
- The counts describe a collect-only comparison. They are not claims about test pass rates.

## What I take from it

Balance the time people wait, then prove that every test still runs exactly once.

## Code and further reading

- [ASH #965: weight test shards by duration](https://github.com/awslabs/automated-security-helper/pull/965)

Covers work from November 2026 Posted November 21, 2026

Also on

- On DEV from Dec 5
- [Hashnode](https://mh0pe.hashnode.dev/slowest-shard)
- In editorial review at HackerNoon
- On daily.dev from Dec 5

- [Build performance](https://mh0pe.github.io/blog/?tag=Build%20performance#topic-developer-tools)
- [CI](https://mh0pe.github.io/blog/?tag=CI#topic-developer-tools)
- [Verification](https://mh0pe.github.io/blog/?tag=Verification#topic-developer-tools)

[See the work behind Automated Security Helper](https://mh0pe.github.io/work/automated-security-helper/)

## Read next.

Infrastructure

### [Support is a matrix, not a version number.](https://mh0pe.github.io/blog/support-is-a-matrix/)

What I learned making Rust bindings reflect both the SDK someone installs and the chip they build for.
