Improve thread voting inefficiencies

Initialize the unordered map to a reasonable
number of buckets and make the move hashes well
distributed. For more see
https://github.com/official-stockfish/Stockfish/pull/4958#issuecomment-1937351190
Also make bestThreadPV and newThreadPV references
so we don't copy entire vectors.

closes https://github.com/official-stockfish/Stockfish/pull/5048

No functional change
This commit is contained in:
mstembera
2024-02-10 15:06:38 -08:00
committed by Disservin
parent 91a4cea437
commit 531747ee78
2 changed files with 4 additions and 6 deletions

View File

@@ -210,10 +210,9 @@ void ThreadPool::start_thinking(const OptionsMap& options,
Thread* ThreadPool::get_best_thread() const {
std::unordered_map<Move, int64_t, Move::MoveHash> votes;
Thread* bestThread = threads.front();
Value minScore = VALUE_NONE;
std::unordered_map<Move, int64_t, Move::MoveHash> votes(2 * std::min(size(), bestThread->worker->rootMoves.size()));
// Find the minimum score of all threads
for (Thread* th : threads)
@@ -232,13 +231,12 @@ Thread* ThreadPool::get_best_thread() const {
const auto bestThreadScore = bestThread->worker->rootMoves[0].score;
const auto newThreadScore = th->worker->rootMoves[0].score;
const auto bestThreadPV = bestThread->worker->rootMoves[0].pv;
const auto newThreadPV = th->worker->rootMoves[0].pv;
const auto& bestThreadPV = bestThread->worker->rootMoves[0].pv;
const auto& newThreadPV = th->worker->rootMoves[0].pv;
const auto bestThreadMoveVote = votes[bestThreadPV[0]];
const auto newThreadMoveVote = votes[newThreadPV[0]];
const bool bestThreadInProvenWin = bestThreadScore >= VALUE_TB_WIN_IN_MAX_PLY;
const bool newThreadInProvenWin = newThreadScore >= VALUE_TB_WIN_IN_MAX_PLY;