This exposes an optional parameter to pass a pre-allocated MoveList to several functions that can use it. In particular, it allows one to pass a pre-allocated MoveList to movefromsan, which is called internally in many places, and which in turn calls moves, which allocates a large MoveList unless otherwise supplied one.
One notable case where this causes a slowdown is in the PGN code, where movetosan is called frequently. This PR also changes readgame and gamesfromfile to pre-allocate a MoveList that is used throughout the game parsing via the newly exposed parameters.
Below is a benchmark on a reasonably long single game to demonstrate. Please note the allocation amount and number.
This exposes an optional parameter to pass a pre-allocated
MoveList
to several functions that can use it. In particular, it allows one to pass a pre-allocatedMoveList
tomovefromsan
, which is called internally in many places, and which in turn callsmoves
, which allocates a largeMoveList
unless otherwise supplied one.One notable case where this causes a slowdown is in the
PGN
code, wheremovetosan
is called frequently. This PR also changesreadgame
andgamesfromfile
to pre-allocate aMoveList
that is used throughout the game parsing via the newly exposed parameters.Below is a benchmark on a reasonably long single game to demonstrate. Please note the allocation amount and number.
Before:
This PR: