From 4038f186d6e3c1ac216babdbfa38e7d9060cb024 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 2 Dec 2026 07:04:31 +0100 Subject: [PATCH] perf(utilities): the worker pool reads the core count once worker_pool::capacity() called std::thread::hardware_concurrency() each time, and every job asks for it, several times a frame. On Windows that call asks the system for the processor layout (GetLogicalProcessorInformationEx) each time: 0.39% of the main thread on Tomaszewo. The count is read once now; the machine doesn't change its cores while the simulator runs. --- utilities/workerpool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utilities/workerpool.cpp b/utilities/workerpool.cpp index 3f0d236e2..237c2fcaf 100644 --- a/utilities/workerpool.cpp +++ b/utilities/workerpool.cpp @@ -34,7 +34,10 @@ std::size_t worker_pool::capacity() { return 1; } - return std::max(1, std::thread::hardware_concurrency()); + // read once: the count asks the system for the processors of the machine (GetLogicalProcessorInformationEx on Windows), + // and the pool is asked for it by every job, several times a frame + static std::size_t const cores{std::max(1, std::thread::hardware_concurrency())}; + return cores; } void worker_pool::grow(std::size_t const Workers)