chess engine performance messed up after optimizations

Hi, i'm writing a chess engine for fun using alpha beta pruning (https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning).

i've changed my whole coordinate system from my own 'vec2' class to just a 'char', and i've also changed my two arrays which point to all the white and black pieces to use this new system, and i also added another array of 64 'char's which point to the index in those two arrays so they can easilly be updated when a piece moves.

I expected that all these things would increase performance, or at least not decrease it, but in reality the program now runs twice as slow. So i fired up msvc's profiler and found a lot of samples in the alphabeta function itself, which is totally unlike the previous version where most of the samples were in the board's copy constructor. Things get really weird when i tell you i DIDN'T change the alphabeta function AT ALL, except some small variable changes to make it use the two arrays pointing to white and black pieces so it doesn't have to loop through all 64 squares. So where are all these extra samples coming from? I have no clue, at least it still seams to output correct moves.

I was too stupid to make a backup of my code when it still worked reasonably fast, i do however have a msvc performance report.

Here's my full Board.cpp file: https://pastebin.com/6uwztucL
Here's the performace report before optimizations: https://www.dropbox.com/s/bvd19vb1heoh4wc/Report20171130-2144.vspx?dl=0
And after optimizations: https://www.dropbox.com/s/ej4r0uw16fb7de9/Report20171202-1241.vspx?dl=0
And a x64 exe compiled in release mode if you feel confident enough that it isn't malware or have a vm setup: https://www.dropbox.com/s/f38h80rgamd32z7/Chess.exe?dl=0

I've spent probably over 6 hours staring at my code and those reports trying to find out what i've messed up or trying to find a reason to why the 'optimized' version is spending so much more time in the alphabeta function compared to the faster not-optimized version and i still have no clue. I've tried '__declspec(noinline)' to see if inlined function were messing with the profiler, but no luck. i've stepped through the code line-by-line and everything seems to work as intended, also no luck.

If you need anything else or have found something that might help, please comment, i'm lost.
Last edited on
Registered users can post here. Sign in or register to post.