Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Improve performance of checking whether a buy causes a loss #73

Merged
merged 1 commit into from Feb 14, 2012

Conversation

Projects
None yet
2 participants
Contributor

bilts commented Feb 14, 2012

I was profiling other performance fixes when I noticed pull request #70 caused a big performance hit. It nearly doubled the execution time of simulations. The hypothetical game state portion of the logic is very expensive. If there was one Province left in the supply, it would be run once per card the current player could afford, on average 70-75 times per game.

I added some early bail-out points: 1) it skips the check if the current buy won't empty a supply pile and 2) it skips the check if the current buy would leave the player in the lead. Performance is pretty much back to what it was. The expensive check is made only a couple of times per game and sometimes not at all.

@bilts bilts Improve performance of checking whether a buy causes a loss
Before cloning the game state, we first check to see if buying the
card in question would cause a pile to empty, and whether the current
player would be in the lead after gaining it.  This cuts the total
Dominiate execution time nearly in half.
797a171

@rspeer rspeer added a commit that referenced this pull request Feb 14, 2012

@rspeer rspeer Merge pull request #73 from bilts/fix-buy-causes-loss-performance
Improve performance of checking whether a buy causes a loss
396cfb0

@rspeer rspeer merged commit 396cfb0 into rspeer:master Feb 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment