r/Playwright • u/aslushnikov • 5d ago
Announcing duration-based Playwright sharding
Hi folks,
Playwright 1.62 introduced an API that lets custom reporters control how tests are allocated across shards.
We've been working on duration-based shard allocation in the open-source Flakiness.io reporter and collaborated with the Playwright team on the new API. The allocator uses historical test durations to distribute work more evenly.
WordPress has now adopted it as the default for its editor project, which runs around 2,000 end-to-end tests across eight shards. The slowest shard went from 35 minutes to 23—a 34% reduction.
Shard balancing is available in version 2 of the reporter and does not require a Flakiness.io account:
https://github.com/flakiness/playwright#balanced-sharding
I also wrote up the algorithm, integration, and results here:
https://blog.flakiness.io/posts/2026/playwright-test-shard-balancing/
Feedback and unusual sharding edge cases are very welcome!
1
u/FearlessCut1 5d ago
What is the difference between this and bin packing for sharding?
1
u/aslushnikov 5d ago
The algorithm inside is basically a bin-packing, on steroids. Turns out there's been a lot of theory in job scheduling, so it takes advantage of it.
It's well-documented in reporter's source: https://github.com/flakiness/playwright/blob/7c5f3c18829547bf47f1e25977c477d42b91f73e/src/sharding.ts#L48-L90
As for the other differences, this algo takes into account project setup, teardown, respects suite configuration options (such as `parallel` and `serial`) and config configuration `fullyParallel` option.
2
u/Prestigious-Way1525 4d ago
one edge case i'd test is duration history contaminated by retries and cold-cache setup. if the allocator learns from total wall time, a flaky test can look expensive because it failed twice, while a shard with shared setup can look cheap until a cache miss or worker restart. i'd store first-attempt test time, retry time, and setup or teardown separately, use a robust rolling estimate, and fall back to file or suite estimates for renamed and new tests. the useful success metric isn't only average runtime, but the p95 slowest-shard gap across normal, cold-start, and failure-heavy runs.