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.
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.