Why is an array declared using a large number of processors and how can it be optimized?

I am writing a chess engine as a training project. To decide what needs to be done, he needs to analyze all the states of the boards that can be achieved by following 4 steps from the current state of the board. This means that I have to analyze hundreds of thousands of boards.

The code is slow to understand, so I used the built-in Netbeans profiler to see which function I should optimize. I was surprised to find that it was just creating new arrays in copied Boardobjects that most processors used.

Here is the function he says uses most CPUs, in particular init1():

private void initializeFields(Color active) {
    init1();
    init2(active);
    init3();
    init4();
}

private void init1() {
    //this line appears to be using a ton of CPU
    pieces = new Piece[SQUARES_PER_SIDE][SQUARES_PER_SIDE];
}

private void init2(Color active) {
    activePlayer = active;
}

private void init3() {
    moveHistory = new LinkedList<>();
}

private void init4() {
    possibleMoves = null;
}

And here are the profiling results:

enter image description here

, , , , , - Board, , CPU. 2 :

1. CPU - Board?

, , . , ?

2. ?

, , , . , 8x8, .

+4
1
  • Board?

, . , - .

  1. ?

, .

, , . ( @shmosel)

+2

Source: https://habr.com/ru/post/1669341/


All Articles