From 7d5e778dfaf99a6a5dd77bff7d4ce67c6bd722e3 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 14 May 2021 00:13:04 +1000 Subject: [PATCH] previewautocacher: multithread hash process Significantly improves hashing speed. Particularly noticeable with longer video sources. --- app/render/previewautocacher.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/render/previewautocacher.cpp b/app/render/previewautocacher.cpp index 4532faeb1..c2ccc968a 100644 --- a/app/render/previewautocacher.cpp +++ b/app/render/previewautocacher.cpp @@ -59,7 +59,7 @@ void PreviewAutoCacher::SetPaused(bool paused) paused_ = paused; } -void PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector ×, qint64 job_time) +void GenerateHashesInternal(ViewerOutput *viewer, FrameHashCache* cache, const QVector ×, qint64 job_time) { std::vector existing_hashes; @@ -87,6 +87,34 @@ void PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cac } } +void PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector ×, qint64 job_time) +{ + // Ensure number of threads doesn't exceed idealThreadCount for maximum concurrency + int hashes_per_thread = times.size() / qMax(1, QThread::idealThreadCount()-1); + + // Somewhat arbitrary (it felt right) number used to determine when the overhead of sending this + // to threads will exceed the benefit of multithreading + static const int kMinimumHashesPerThread = 500; + if (hashes_per_thread < kMinimumHashesPerThread) { + hashes_per_thread = kMinimumHashesPerThread; + } + + // Queue threaded tasks for each + if (hashes_per_thread >= times.size()) { + // Don't bother queuing in other thread, just run + GenerateHashesInternal(viewer, cache, times, job_time); + } else { + QVector > threads; + for (int i=0; i