Run independent arena games in parallel - #25
Merged
Merged
Conversation
Real-LLM benchmarks spend almost all their wall-clock waiting on the provider: games are independent, so dispatching them onto a thread pool scales close to linearly with worker count. Aggregation is commutative, so the report is bit-identical to the sequential run regardless of completion order. - Arena.run gains `max_workers: int = 1` (keyword-only). >1 runs games through a ThreadPoolExecutor with a lock around _record. Default is unchanged. - Leaderboard.run threads max_workers into the inner Arena runs. - CLI: --workers N on `deepwolf arena` and `deepwolf leaderboard`. - Documented the thread-safety expectation (agents that share mutable state — notably MockProvider's RNG — should be instantiated per game by the factory). - 3 new arena tests: bit-for-bit match vs sequential, progress hook coverage, default-is-sequential. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
Code review (post-merge record).
Solid optimisation. Merged via squash. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code-optimisation half of this maintenance cycle.
Independent arena games can now run in parallel via a thread pool. Real-LLM benchmarks spend almost all their wall-clock waiting on the provider (HTTP IO releases the GIL), so this scales close to linearly with worker count for the cases that actually matter. Aggregation is commutative —
Arena._recordunder a single lock — so the resultingArenaReportis bit-identical to the sequential run regardless of completion order.Changes
Arena.rungainsmax_workers: int = 1(keyword-only). With >1, games are dispatched onto aThreadPoolExecutor; recording is serialised under a lock; progress hook fires per game in completion order. Default behaviour unchanged.Leaderboard.runthreadsmax_workersinto the innerArena.runcalls.--workers Nondeepwolf arenaanddeepwolf leaderboard.MockProvider's RNG — should be instantiated per game by the factory in parallel mode. Factories that return fresh agents (the usual pattern) are safe automatically.Why threads, not processes
For real-LLM use the bottleneck is network IO, which releases the GIL → threads scale linearly. Processes would require picklable factories (lambdas don't pickle) and would add startup overhead. The library's existing API is preserved exactly.
Checklist
ruff/mypy/pytest(92 tests, 3 new) all passtest_parallel_arena_matches_sequential_bit_for_bit)