Skip to content

feat(mutation): balance the scoped shards by expected time - #71

Merged
sinemacula-ben merged 2 commits into
masterfrom
feature/cost-balanced-mutation-shards
Oct 11, 2026
Merged

sinemacula-ben merged 2 commits into
masterfrom
feature/cost-balanced-mutation-shards

Conversation

@sinemacula-ben

Copy link
Copy Markdown
Contributor

Draft until it is proven against a consumer.

The scoped plan split the changed files across shards by line count. Cost per mutant varies widely when some files are covered only by slow tests that drive the whole application, so shards of similar size can take very different times: in one run, two shards of about 390 mutants took 18 and 102 minutes, and the slowest shard set the gate's wall clock.

Stryker's report records no test times (TestDefinition is id, name and location; duration is never filled), so the only measured times are the sharded full sweep's per-shard timings. This makes those timings finer and lets the scoped plan use them.

Change Detail
Sweep timings measureSweep shares each full shard's measured seconds out per mutant by the tests it ran, each test weighed by how many mutants it covers against the average test (a static mutant's tests count as average). With equal tests this is the old 1 + testsCompleted weight. The history keeps files and adds lines: [line, mutants, seconds] per mutated line. Same cache key, so older workflow versions still read files
Scoped estimate estimateScope: a measured whole file costs what it took; a range costs the larger of its recorded lines' seconds and the file's average per line, so code added since the sweep still counts; a file the sweep never saw costs the sweep's average per line. A history without lines costs ranges by the file's average
Scoped packing planScope: longest first onto the least loaded shard, ties to the shard with fewer units. A file heavier than a fair share is still split by its ranges, now judged by cost; a range is never cut
Fallback No history, an unreadable one, or no usable entries: line-count balancing as before. An estimation error logs a warning and falls back; it never fails the plan
Visibility The plan logs and summarises each shard's estimated minutes, or its lines on the fallback, and says which basis it used
Wiring Mutation plan checks out .github/scripts at the workflow's commit and restores the sweep timings, which the default branch writes and pull requests can read. The inline plan is now an ES module importing the library

The full sweep's planner already packed whole files by measured time; it now gets the finer per-mutant weighting through the same history. No input changes; callers need nothing new.

Offline: node --test (27 tests, including uneven cost, new lines and new files, a v1 history, missing, malformed and overflowing histories, and range splitting by cost), qlty check and qlty smells against origin/master, and the extracted plan script run against a scratch repository with no history, a v2 history, and malformed and truncated histories. On the line-count fallback, loads match the old plan; only which of two equally loaded shards gets a unit can differ.

The scoped plan split the changed files by line count, so shards with
similar counts could take very different times when some files are
covered only by slow, wide tests.

Stryker's report records no test times, so the full sweep now shares each
shard's measured time out per mutant by the tests it ran, each weighed by
how many mutants it covers, and saves seconds per mutated line alongside
seconds per file. The scoped plan restores those timings and estimates
each file or range from them: a measured file at what it took, a range at
the larger of its lines' time and the file's average per line, and a file
the sweep never saw at the sweep's average per line. It packs the units
longest first onto the least loaded shard, still splitting an expensive
file by its ranges, and logs each shard's estimated minutes.

Without timings, or with unreadable ones, it balances by line count as
before. No caller changes are needed.
@sinemacula-ben
sinemacula-ben marked this pull request as ready for review October 11, 2026 22:49
@sinemacula-ben
sinemacula-ben merged commit b55a0a1 into master Oct 11, 2026
6 checks passed
@sinemacula-ben
sinemacula-ben deleted the feature/cost-balanced-mutation-shards branch October 11, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant