From 5c2796a07955f430f14382a8ace30791a2847a04 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 22 Aug 2024 22:41:12 +0200 Subject: [PATCH] Limit gui thread pool to 8 threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid having too many threads, since iOS punishes us if we overstep 64, and we don't really need more than 8 on any platform. Fixes: QTBUG-128290 Pick-to: 6.7 6.5 Change-Id: I59a233d422e9b1b2097a777e0b1b626e144594d9 Reviewed-by: Tor Arne Vestbø Reviewed-by: Thiago Macieira (cherry picked from commit 80f210db3e43c50e252504f41ed3fbd8b2992028) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/thread/qthreadpool.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index c7531111da7..f4dc940cc4b 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -481,8 +481,13 @@ QThreadPool *QThreadPoolPrivate::qtGuiInstance() Q_CONSTINIT static QBasicMutex theMutex; const QMutexLocker locker(&theMutex); - if (guiInstance.isNull() && !QCoreApplication::closingDown()) + if (guiInstance.isNull() && !QCoreApplication::closingDown()) { guiInstance = new QThreadPool(); + // Limit max thread to avoid too many parallel threads. + // We are not optimized for much more than 4 or 8 threads. + if (guiInstance && guiInstance->maxThreadCount() > 4) + guiInstance->setMaxThreadCount(qBound(4, guiInstance->maxThreadCount() / 2, 8)); + } return guiInstance; }