Skip to content

Fix quadratic build time when many infosets are emptied in game generators#880

Open
d-kad wants to merge 1 commit into
gambitproject:masterfrom
d-kad:removemember-quad
Open

Fix quadratic build time when many infosets are emptied in game generators#880
d-kad wants to merge 1 commit into
gambitproject:masterfrom
d-kad:removemember-quad

Conversation

@d-kad
Copy link
Copy Markdown
Contributor

@d-kad d-kad commented May 22, 2026

Fix quadratic build time during incremental tree construction

GameTreeRep::RemoveMember called RenumberInfosets unconditionally when
an 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.

GameTreeRep already provides EnsureInfosetOrdering() as a lazy canonicalization,
and all public reads of GameInfosetRep::GetNumber should use it.

This PR:

  • removes the eager RenumberInfosets from RemoveMember;

  • makes GameInfosetRep::GetNumber() pass through EnsureInfosetOrdering
    explicitly, mirroring GameNodeRep::GetNumber().

For a 524K-node binary tree with sibling merging, 10 iterations of
build + is_subgame_root drop 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.

@d-kad d-kad requested review from rahulsavani and tturocy May 22, 2026 07:08
@d-kad d-kad added c++ Items which involve writing in C++ bug enhancement tests Items which involve the pygambit test suite labels May 22, 2026
@d-kad d-kad added this to the gambit-16.7.0 milestone May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug c++ Items which involve writing in C++ enhancement tests Items which involve the pygambit test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant