Hello there, i am currently optimizing the move generator of the chess engine i am currently writing. Everything was going smoothly until i checked my profiles. My code is spending 81% of the time not generating moves, but writing them into the result list. Being a bit baffled at first, i triple checked this result until i convinced myself that even though i am writing into an already allocated array, which i am passing by pointer this is infact tanking my performance.
This is the function that is spend 81% of my time in (this function is inlined by the compiler):
func commitMoveBoard(moveList *[120]Move, moveCount int, mb bitmap.Bitmap, pieceType PieceType, origin int8, board *Board) int {
for mb != 0 {
square := mb.Scan()
moveList[moveCount] = Move{
Origin: Square(origin),
Destination: Square(square),
PieceType: pieceType,
CapturedPieceType: board.SquareCache[square].Type,
}
moveCount++
mb &= mb - 1
}
return moveCount
}
Does anyone have an idea how i could improve this?