Optimize MCTS playout performance (~2.4x speedup)#371
Open
cullback wants to merge 2 commits intobcollazo:masterfrom
Open
Optimize MCTS playout performance (~2.4x speedup)#371cullback wants to merge 2 commits intobcollazo:masterfrom
cullback wants to merge 2 commits intobcollazo:masterfrom
Conversation
- Cache player_key strings to avoid 138M f-string allocations per run - Switch Color, ActionType, ActionPrompt, NodeRef, EdgeRef to IntEnum for faster hashing (171M calls) - Optimize longest_acyclic_path: visited-set mutation instead of list copying, DFS only from leaves/branch points, leaf extension fast path - Add Game.play_random() to skip action validation in random playouts
Both accumulators skip tracking when there's no winner (turn limit reached). The summary code then divides by zero. Guard all division sites in play.py and accumulators.py.
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
"P0","P1"prefixes inState.__init__instead of constructing via f-string on every call (was 138M calls / 26s)Color,ActionType,ActionPrompt,NodeRef,EdgeRefnow useIntEnumfor faster hashing (was 171M calls / 17.5s)Game.play_random(): Lightweight playout loop that skips action validation overheadProfiled with
catanatron-play --players M:5,M:5 --num 2 --config-vps-to-win 15 --config-discard-limit 9:Test plan
python -m pytest tests/passeslongest_acyclic_path,player_key, and enum hashing