Fix quadratic build time when many infosets are emptied in game generators#880
Open
d-kad wants to merge 1 commit into
Open
Fix quadratic build time when many infosets are emptied in game generators#880d-kad wants to merge 1 commit into
d-kad wants to merge 1 commit into
Conversation
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.
Fix quadratic build time during incremental tree construction
GameTreeRep::RemoveMembercalledRenumberInfosetsunconditionally whenan infoset became empty, doing O(
player.infosets.size()) work on every call.I noticed this while profiling the subgame-roots checker on a depth-18 binary game
(~524K nodes), where build time dominated and ran into the minutes per game.
The current pattern is building a perfect-information tree and then merging siblings
into shared infosets via SetInfoset. Each merge empties a singleton infoset and triggers
the renumber: a linear sequence of merges becomes quadratic.
GameTreeRepalready providesEnsureInfosetOrdering()as a lazy canonicalization,and all public reads of
GameInfosetRep::GetNumbershould use it.This PR:
removes the eager
RenumberInfosetsfromRemoveMember;makes
GameInfosetRep::GetNumber()pass throughEnsureInfosetOrderingexplicitly, mirroring
GameNodeRep::GetNumber().For a 524K-node binary tree with sibling merging, 10 iterations of
build +
is_subgame_rootdrop from 12 min 20 s to 1 min 45 s.The speedup is entirely in the build phase; subgame detection itself is unaffected by this patch.