bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JProfiler, Perft and performance observations

osvitashev opened this issue · comments

I decided to run Perft function with JProfiler.
Overall, Perft runs at about 3 million nodes/second on my machine, which is pretty slow, but i realize that Java is supposed to be slower than C++. For comparison, kz04px/libchess which is written in C++ runs at about 50 million nodes/second.
Here are some observations:

  • LinkedList.add and LinkedList.addLast together contribute to 30% of both CPU and memory allocation time. Perhaps LinkedList is not the best choice for storing legal moves and move history, due to the memory being allocated incrementally?
  • Long.valueOf takes about 10% of CPU and memory allocation time. Seems like there might be some extra conversion between java primitive and object wrapper.
  • MoveBackup and EnumMap take up about 10% or resources each. Perhaps, EnumMap has too much of a footprint for a structure which essentially only stores four boolean flags.
  • Board.doMove takes about 15% of resources. Here, i am not sure what can be improved, at the moment.

I might take a stab at these at some point. Below are JProfiler screenshots. Let me know is i am on a totally wrong track.

image

image