From 5a070f14de6eb92428c0b391487c60584d75e136 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 20 Feb 2020 17:48:50 +1100 Subject: [PATCH] general: use IdlePriority rather than LowPriority Fixes a number of playback stuttering and general UI lag issues by setting all background tasks to IdlePriority rather than LowPriority. While it was assumed LowPriority tasks would always get scheduled below NormalPriority (e.g. main thread) tasks, it turns out this is not always the case. If the background tasks start consuming a lot of CPU cycles, the scheduler may use "dynamic scheduling" to schedule them above the main thread regardless leading to UI lag. This is apparently the case for all thread priorities apart from IdlePriority, which is allegedly a special case where threads are *only* scheduled when other threads aren't busy ensuring the main thread stays responsive. --- app/audio/audiomanager.cpp | 2 +- app/dialog/task/task.cpp | 2 +- app/render/backend/opengl/openglbackend.cpp | 2 +- app/render/backend/renderbackend.cpp | 2 +- app/task/taskmanager.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/audio/audiomanager.cpp b/app/audio/audiomanager.cpp index e3c897606..3ce9abd8a 100644 --- a/app/audio/audiomanager.cpp +++ b/app/audio/audiomanager.cpp @@ -59,7 +59,7 @@ void AudioManager::RefreshDevices() QThread* thread = new QThread(); connect(thread, &QThread::finished, thread, &QThread::deleteLater); - thread->start(QThread::LowPriority); + thread->start(QThread::IdlePriority); AudioRefreshDevicesObject* refresher = new AudioRefreshDevicesObject(); connect(refresher, &AudioRefreshDevicesObject::ListsReady, this, &AudioManager::RefreshThreadDone); diff --git a/app/dialog/task/task.cpp b/app/dialog/task/task.cpp index 88ded60bc..15ba2eb2c 100644 --- a/app/dialog/task/task.cpp +++ b/app/dialog/task/task.cpp @@ -34,7 +34,7 @@ void TaskDialog::open() } // Create a separate thread to run this task in - thread_->start(QThread::LowPriority); + thread_->start(); // Move the task to this thread task_->moveToThread(thread_); diff --git a/app/render/backend/opengl/openglbackend.cpp b/app/render/backend/opengl/openglbackend.cpp index 5d40cba10..f286023de 100644 --- a/app/render/backend/opengl/openglbackend.cpp +++ b/app/render/backend/opengl/openglbackend.cpp @@ -25,7 +25,7 @@ bool OpenGLBackend::InitInternal() proxy_ = new OpenGLProxy(); proxy_->SetParameters(params()); QThread* proxy_thread = new QThread(); - proxy_thread->start(QThread::LowPriority); + proxy_thread->start(QThread::IdlePriority); proxy_->moveToThread(proxy_thread); if (!proxy_->Init()) { diff --git a/app/render/backend/renderbackend.cpp b/app/render/backend/renderbackend.cpp index 1113a3b3a..bbdeff699 100644 --- a/app/render/backend/renderbackend.cpp +++ b/app/render/backend/renderbackend.cpp @@ -35,7 +35,7 @@ bool RenderBackend::Init() threads_.replace(i, thread); // We use low priority to keep the app responsive at all times (GUI thread should always prioritize over this one) - thread->start(QThread::LowPriority); + thread->start(QThread::IdlePriority); } cancel_dialog_->SetWorkerCount(threads_.size()); diff --git a/app/task/taskmanager.cpp b/app/task/taskmanager.cpp index 024d5f18f..e7903e6f2 100644 --- a/app/task/taskmanager.cpp +++ b/app/task/taskmanager.cpp @@ -34,7 +34,7 @@ TaskManager::TaskManager() : for (int i=0;istart(QThread::LowPriority); + t->start(QThread::IdlePriority); threads_.replace(i, {t, false}); } }