Skip to content

move_picker: swap-and-reduce for TT move - #191

Merged
clarashepherd merged 1 commit into
mainfrom
clara/reduce-picker-iterations
Jul 27, 2025
Merged

move_picker: swap-and-reduce for TT move#191
clarashepherd merged 1 commit into
mainfrom
clara/reduce-picker-iterations

Conversation

@clarashepherd

@clarashepherd clarashepherd commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

Instead of leaving null 'holes' in the move picker, we move picked moves to the back of the array of all moves and reduce the size accordingly.

Bench has changed, because quiet moves at the root have no history, and therefore picked in their order of generation. So changing the move order has large effects down the search.

https://openbench.bunny.beer/test/564/

Bench 1513294

@hansbinderup hansbinderup left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Mostly minors but I think that we can squeeze out even more performance from this 🚀

Comment thread src/search/move_picker.h Outdated
}

private:
movegen::Move pickMove(uint16_t pos)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might improve performance a bit - it's a smaller method, so most likely worth it :)

Suggested change
movegen::Move pickMove(uint16_t pos)
inline movegen::Move pickMove(uint16_t pos)

Comment thread src/search/move_picker.h Outdated
return std::nullopt;

m_moves.nullifyMove(i);
assert(!m_moves[m_syzygyHead].isNull());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need to check for null anymore - movegen does not generate nullmoves :)

Comment thread src/search/move_picker.h Outdated

for (uint16_t i = 0; i < m_moves.count(); i++) {
for (uint16_t i = 0; i < m_size; i++) {
if (!m_moves[i].isNull() && m_moves[i] == *m_ttMove) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check for null-move anymore :) (goes for all the picking now stages)

Suggested change
if (!m_moves[i].isNull() && m_moves[i] == *m_ttMove) {
if (m_moves[i] == *m_ttMove) {

Comment thread src/search/move_picker.h Outdated
std::optional<movegen::Move> bestMove { std::nullopt };
int32_t bestScore = std::numeric_limits<int32_t>::min();
uint16_t bestMoveIndex {};
bool foundBestMove { false };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably cleaner to use a std::optional for the index as it's used to pick the move :)

Comment thread src/search/move_picker.h Outdated
std::optional<movegen::Move> bestMove {};
int32_t bestScore = std::numeric_limits<int32_t>::min();
uint16_t bestMoveIndex {};
bool foundBestMove { false };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here ^

Comment thread src/search/move_picker.h Outdated

movegen::ValidMoves m_moves {};
std::array<int32_t, s_maxMoves> m_scores {};
uint16_t m_size {};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to align with the head used for syzygy :)

Suggested change
uint16_t m_size {};
uint16_t m_tail {};

Comment thread src/search/move_picker.h
movegen::ValidMoves m_moves {};
std::array<int32_t, s_maxMoves> m_scores {};
uint16_t m_size {};
uint16_t m_syzygyHead {};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment to each of these to explain how they're not connected (syzygy we pick from the front and otherwise we move the picked move to the back and decrease the tail etc)

Comment thread src/search/move_picker.h Outdated
private:
movegen::Move pickMove(uint16_t pos)
{
auto pickedMove = m_moves[pos];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto pickedMove = m_moves[pos];
const auto pickedMove = m_moves[pos];

@hansbinderup hansbinderup linked an issue Jul 21, 2025 that may be closed by this pull request
@clarashepherd
clarashepherd force-pushed the clara/reduce-picker-iterations branch from b9c1219 to d963bf0 Compare July 26, 2025 11:24

@hansbinderup hansbinderup left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 💯

Comment thread src/search/move_picker.h Outdated
}

constexpr std::optional<movegen::Move> pickTtMove()
constexpr std::optional<movegen::Move>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: line break

@clarashepherd
clarashepherd force-pushed the clara/reduce-picker-iterations branch from d963bf0 to 78b9302 Compare July 27, 2025 11:30
Instead of leaving null 'holes' in the move picker, we move picked
moves to the back of the array of all moves and reduce the size
accordingly.

Bench has changed, because quiet moves at the root have no history, and
are therefore picked in their order of generation. So changing the move
order has large effects down the search.

Bench 1446371
@clarashepherd
clarashepherd force-pushed the clara/reduce-picker-iterations branch from 78b9302 to b7b0066 Compare July 27, 2025 11:31
@clarashepherd
clarashepherd enabled auto-merge (rebase) July 27, 2025 11:32
@clarashepherd
clarashepherd merged commit 39c2d61 into main Jul 27, 2025
6 checks passed
@clarashepherd
clarashepherd deleted the clara/reduce-picker-iterations branch July 27, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce MovePicker search iterations

2 participants