Skip to content

Commit c65bd9b

Browse files
committed
Set option "Threads" first to speed up the rest of the engine init
1 parent dbf4b73 commit c65bd9b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

projects/lib/src/chessengine.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,32 @@ void ChessEngine::start()
235235

236236
void ChessEngine::onProtocolStart()
237237
{
238+
const char *uciOptionThreads = "Threads";
239+
const char *xboardOptionThreads = "cores";
240+
QMap<QString, QVariant>::const_iterator i;
241+
238242
m_protocolStartTimer->stop();
239243
m_pinging = false;
240244
setState(Idle);
241245
Q_ASSERT(isReady());
242246

243247
flushWriteBuffer();
244248

245-
QMap<QString, QVariant>::const_iterator i = m_optionBuffer.constBegin();
249+
// We'll set the threads option before anything else. On many engines, this will speed up hash init
250+
i = m_optionBuffer.constFind(uciOptionThreads);
251+
if (i != m_optionBuffer.constEnd())
252+
setOption(i.key(), i.value());
253+
254+
i = m_optionBuffer.constFind(xboardOptionThreads);
255+
if (i != m_optionBuffer.constEnd())
256+
setOption(i.key(), i.value());
257+
258+
i = m_optionBuffer.constBegin();
246259
while (i != m_optionBuffer.constEnd())
247260
{
248-
setOption(i.key(), i.value());
261+
if ((i.key() != uciOptionThreads) && (i.key() != xboardOptionThreads))
262+
setOption(i.key(), i.value());
263+
249264
++i;
250265
}
251266
m_optionBuffer.clear();

0 commit comments

Comments
 (0)