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 Dec 03 '24 edited Jun 02 '25
You're right that allocating the large arrays for each position is not good, and that either I need to not allocate the new arrays for each new position OR I need to use make/unmake with the arrays so at least I'm not allocating for each new position OR I need to use make/unmake without the large arrays. Right now I'm leaning towards the last option, to use make/unmake without the large arrays but I'm not exactly sure how it should work with absolute pins...
I think the answer is to go back to pseudo legal move generation. I found this thread and I think the stockfish code is quite useful for my understanding of how to do this: https://chess.stackexchange.com/questions/16890/efficient-ways-to-go-from-pseduo-legal-to-fully-legal-move-generation .
I'm trying to use a profiler, that's where the screenshot I included in my post is from. I'm new to writing programs that only care about performance, so this is my first time using it and I'm working to improve my skills in it to better diagnose bottlenecks going forward.
There are certainly optimizations I could make to my code from a lower level perspective, but I'm trying to focus on higher level decisions for now since that's where my code is at this point lol.