i'm using the tool DotTracelithander wrote: ↑Sun Mar 07, 2021 12:50 pmThanks for taking the time to look into my code! Much appreciated. What tool are you using for the profiling?spirch wrote: ↑Sun Mar 07, 2021 2:26 am also, i saw your link in your signature, i don't know if you ever did a profiling run on your engine, here is one with peft 5
i don't know anything about the code but first thing i would say, remove the recursive call to perft, there is a cost there but you can also look at some hotspot and see if there anything to do there to optimize it
I'm using Visual Studio IDE and of course I did a few profiling runs every now and then. That my perft runs only at 10M Nodes/s is not any fault of the C# language but comes down to a few design decisions motivated by my pledge to write code that's simple and easy to understand.
For example you may notice that CollectMoves takes twice as long as AddMoves. What *else* is it spending time on if not adding moves?? It's scanning the board looking for pieces of the active color. Piece lists could speed this up but other then speeding up the search it doesn't really *add* any value, it just makes things faster and more complicated. Also it would make the board instance "fatter" and I make a *lot* of copies of board instances. (Also visible in your profiler)
Your profiler doesn't add these values up but Consider is actually called on *each* pseudo-legal move to make sure it's legal. How do you make sure of that? You play the move and look if it puts your king in check. That's costly. You have to create a new Board instance (because I also didn't implement Undo for above state reasons) play the Move, scan the board for the king and test if the square he's on is attacked. Once you have that boolean result you let the Garbage Collector mop up the mess because there's a whole board instance created that noone needs anymore. Poor thing.
The garbage collector is good at it though. The process doesn't exceed 18MB of allocated memory. So it's not really a memory leak or anything, it's how C# is supposed to be used. 10M Nodes/s is nothing to brag about, though, and if you care about performance don't do it like me!
When I started I didn't know that the chess programming community would be so competitive about speed. I like it. But I won't try to optimize Minimal Chess retroactively for speed because there *is* a price to be paid for every optimization. It doesn't fit my vision for it. My next chess engine, if I stick with this surprisingly addictive hobby, will be more ambitious in that regard.
i also use visual studio, still under .net framework, i should move to .net core one day
my "collectmoves" method are my "pseudoPiece" methods(these one take a from X and collect all the moves), the ".check." namespace/methods are the one that verify if the king is in check or not, the check method call the "legalmove" methods(these one take a from X to Y and make sure it's 100% valid)
while the perft is running, i create zero instance of anything on my side, i didn't go oriented object
I got a few helper array that I update while perft is running, i have one that know the position of each pieces so i don't need to loop through the board, i know where are the king, i know which piece could attack the kings
i should replace my pseudoPiece method with array that have pre-calculated move, that should speed up thing... hmm i might try that