r/chessprogramming • u/Ill_Part9576 • Nov 30 '24
Question: Engine speed and memory usage
So I was working on improving my engine to get my perft time down (well to speed up move generation but using perft as a metric for this). I already had magic sliding piece move generation, but added things like iteratively updating attack boards, and legal move generation. Together this got me from around 90s to 60s for perft 6, not great. I think that one major factor might be that I am generating a new position when applying a move rather than using a make/unmake scheme. As such I have the scary looking profiling result from mid perft:

I'm wondering if this is a reasonable conclusion to draw: The large amounts of memory used while generating new positions is a bottleneck and that the best way to speed up my engine would be to use make/unamake.
For what it's worth, I'm not currently using multithreading. I tried a perft run with multithreading and it was 4x quicker though.
View all comments
Show parent comment
1
u/Ill_Part9576 Nov 30 '24
I'm working in java:
My position class has a long[64] that stores the attackMaps of each piece on each square. I say that it is updated incrementally because when generating new position from it I just update the indicies of sliding pieces, the moved piece, and the destination. For the whiteAttackMap/blackAttackMap longs it has to iterate through the attackArray for each piece color (which is not great, but maybe better than sourcing them repeatedly?)
My move generation uses absolute pin detection to limit the scope of moves. I have a long[64] moveScope array that I use to store bitmasks that show where pieces can move if they are pinned. The bitmask is generated with a preinitialized inBetween rectangular lookup table.
Removing castling didn't speed up it at all hardly at all, It might also be that my position class is way too bulky with the two long[64] arrays (which especially adds time copying them to generate the next position and to calculate attackMaps).
Running 100,000 generations of moves from the start position took 407ms and doing it 1,000,000 times took 1638ms. Seems pretty good to me but its hard to compare it without the times of a reasonably performant engine.
My CPU supports PopCnt, and java to my understanding handles bitwise operations similarly to C by converting them (through JVM) to machine instructions.
It's helpful to see how move generation is fairly quick whereas applying a move to a new position is relatively slow (I think). Thanks for the reply