From 0bc176fd62382249c4b270b8116b1c9622989628 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 17 Jan 2020 04:37:47 +1100 Subject: [PATCH] use less threads on cache By using one thread per logical CPU thread, we seemed to completely saturate the CPU which would kill the performance of the main/GUI thread (despite the other threads being low priority). We now use half of the logical threads, which still sees good CPU usage and minimal performance impact while allowing the main thread to respond to user actions. --- app/render/backend/audiorenderbackend.cpp | 8 ++++---- app/render/backend/opengl/openglbackend.cpp | 1 - app/render/backend/opengl/openglframebuffer.cpp | 5 ++--- app/render/backend/renderbackend.cpp | 2 +- app/render/diskmanager.cpp | 10 ++++++++-- app/render/diskmanager.h | 2 ++ 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/render/backend/audiorenderbackend.cpp b/app/render/backend/audiorenderbackend.cpp index 9a4a52df5..7765e1902 100644 --- a/app/render/backend/audiorenderbackend.cpp +++ b/app/render/backend/audiorenderbackend.cpp @@ -29,14 +29,14 @@ void AudioRenderBackend::SetParameters(const AudioRenderingParams ¶ms) void AudioRenderBackend::ConnectViewer(ViewerOutput *node) { - connect(node, SIGNAL(AudioChangedBetween(const rational&, const rational&)), this, SLOT(InvalidateCache(const rational&, const rational&))); - connect(node, SIGNAL(AudioGraphChanged()), this, SLOT(QueueRecompile())); + connect(node, &ViewerOutput::AudioChangedBetween, this, &AudioRenderBackend::InvalidateCache); + connect(node, &ViewerOutput::AudioGraphChanged, this, &AudioRenderBackend::QueueRecompile); } void AudioRenderBackend::DisconnectViewer(ViewerOutput *node) { - disconnect(node, SIGNAL(AudioChangedBetween(const rational&, const rational&)), this, SLOT(InvalidateCache(const rational&, const rational&))); - disconnect(node, SIGNAL(AudioGraphChanged()), this, SLOT(QueueRecompile())); + disconnect(node, &ViewerOutput::AudioChangedBetween, this, &AudioRenderBackend::InvalidateCache); + disconnect(node, &ViewerOutput::AudioGraphChanged, this, &AudioRenderBackend::QueueRecompile); } bool AudioRenderBackend::GenerateCacheIDInternal(QCryptographicHash &hash) diff --git a/app/render/backend/opengl/openglbackend.cpp b/app/render/backend/opengl/openglbackend.cpp index bae321ef7..aa49df222 100644 --- a/app/render/backend/opengl/openglbackend.cpp +++ b/app/render/backend/opengl/openglbackend.cpp @@ -61,7 +61,6 @@ OpenGLTexturePtr OpenGLBackend::GetCachedFrameAsTexture(const rational &time) if (cached_frame != nullptr) { master_texture_->Upload(cached_frame); - return master_texture_; } diff --git a/app/render/backend/opengl/openglframebuffer.cpp b/app/render/backend/opengl/openglframebuffer.cpp index 8da990c5d..1de405420 100644 --- a/app/render/backend/opengl/openglframebuffer.cpp +++ b/app/render/backend/opengl/openglframebuffer.cpp @@ -28,7 +28,6 @@ OpenGLFramebuffer::OpenGLFramebuffer() : buffer_(0), texture_(nullptr) { - } OpenGLFramebuffer::~OpenGLFramebuffer() @@ -48,7 +47,7 @@ void OpenGLFramebuffer::Create(QOpenGLContext *ctx) context_ = ctx; - connect(context_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Destroy())); + connect(context_, &QOpenGLContext::aboutToBeDestroyed, this, &OpenGLFramebuffer::Destroy); // Create framebuffer object context_->functions()->glGenFramebuffers(1, &buffer_); @@ -57,7 +56,7 @@ void OpenGLFramebuffer::Create(QOpenGLContext *ctx) void OpenGLFramebuffer::Destroy() { if (context_ != nullptr) { - disconnect(context_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Destroy())); + disconnect(context_, &QOpenGLContext::aboutToBeDestroyed, this, &OpenGLFramebuffer::Destroy); context_->functions()->glDeleteFramebuffers(1, &buffer_); diff --git a/app/render/backend/renderbackend.cpp b/app/render/backend/renderbackend.cpp index 5d277b707..d6e5f2b04 100644 --- a/app/render/backend/renderbackend.cpp +++ b/app/render/backend/renderbackend.cpp @@ -20,7 +20,7 @@ bool RenderBackend::Init() return true; } - threads_.resize(QThread::idealThreadCount()); + threads_.resize(qMax(1, QThread::idealThreadCount() / 2)); for (int i=0;i #include #include +#include #include "common/filefunctions.h" #include "config/config.h" @@ -15,7 +16,7 @@ DiskManager::DiskManager() : consumption_(0) { // Try to load any current cache index from file - QFile cache_index_file(QDir(GetMediaCacheLocation()).filePath("index")); + QFile cache_index_file(GetCacheIndexFilename()); if (cache_index_file.open(QFile::ReadOnly)) { QDataStream ds(&cache_index_file); @@ -43,7 +44,7 @@ DiskManager::~DiskManager() ClearDiskCache(); } else { // Save current cache index - QFile cache_index_file(QDir(GetMediaCacheLocation()).filePath("index")); + QFile cache_index_file(GetCacheIndexFilename()); if (cache_index_file.open(QFile::WriteOnly)) { QDataStream ds(&cache_index_file); @@ -172,3 +173,8 @@ qint64 DiskManager::DiskLimit() // Convert gigabytes to bytes return qRound64(gigabytes * 1073741824); } + +QString DiskManager::GetCacheIndexFilename() +{ + return QDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("diskindex"); +} diff --git a/app/render/diskmanager.h b/app/render/diskmanager.h index 9fe27daa8..d7ecb8b2f 100644 --- a/app/render/diskmanager.h +++ b/app/render/diskmanager.h @@ -36,6 +36,8 @@ private: qint64 DiskLimit(); + static QString GetCacheIndexFilename(); + struct HashTime { QString file_name; QByteArray hash;