From 2b20d5b2602889c8fb3a04bde9e0ecb841760d7f Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Mon, 16 Jan 2023 14:45:12 +0300 Subject: [PATCH] Fix startup performance on Qt5 Use more appropriate container (QList) for resume data queue buffer. QVector in Qt5 has poor performance of the first element taking operation, which is used to process the resume data queue. In Qt6, QVector is just an alias for QList, so there was no problem there. PR #18387. Fixes #18341. --- src/base/bittorrent/resumedatastorage.cpp | 5 +++-- src/base/bittorrent/resumedatastorage.h | 6 +++--- src/base/bittorrent/sessionimpl.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/base/bittorrent/resumedatastorage.cpp b/src/base/bittorrent/resumedatastorage.cpp index 0b640a95e..6e67a5b58 100644 --- a/src/base/bittorrent/resumedatastorage.cpp +++ b/src/base/bittorrent/resumedatastorage.cpp @@ -33,6 +33,7 @@ #include #include #include +#include const int TORRENTIDLIST_TYPEID = qRegisterMetaType>(); @@ -59,11 +60,11 @@ void BitTorrent::ResumeDataStorage::loadAll() const loadingThread->start(); } -QVector BitTorrent::ResumeDataStorage::fetchLoadedResumeData() const +QList BitTorrent::ResumeDataStorage::fetchLoadedResumeData() const { const QMutexLocker locker {&m_loadedResumeDataMutex}; - const QVector loadedResumeData = m_loadedResumeData; + const QList loadedResumeData = m_loadedResumeData; m_loadedResumeData.clear(); return loadedResumeData; diff --git a/src/base/bittorrent/resumedatastorage.h b/src/base/bittorrent/resumedatastorage.h index 3faf63494..b583da60a 100644 --- a/src/base/bittorrent/resumedatastorage.h +++ b/src/base/bittorrent/resumedatastorage.h @@ -29,9 +29,9 @@ #pragma once #include +#include #include #include -#include #include "base/3rdparty/expected.hpp" #include "base/path.h" @@ -65,7 +65,7 @@ namespace BitTorrent virtual void storeQueue(const QVector &queue) const = 0; void loadAll() const; - QVector fetchLoadedResumeData() const; + QList fetchLoadedResumeData() const; signals: void loadStarted(const QVector &torrents); @@ -78,7 +78,7 @@ namespace BitTorrent virtual void doLoadAll() const = 0; const Path m_path; - mutable QVector m_loadedResumeData; + mutable QList m_loadedResumeData; mutable QMutex m_loadedResumeDataMutex; }; } diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 14a5735fe..5fa4cb699 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -340,7 +340,7 @@ struct BitTorrent::SessionImpl::ResumeSessionContext final : public QObject ResumeDataStorage *startupStorage = nullptr; ResumeDataStorageType currentStorageType = ResumeDataStorageType::Legacy; - QVector loadedResumeData; + QList loadedResumeData; int processingResumeDataCount = 0; int64_t totalResumeDataCount = 0; int64_t finishedResumeDataCount = 0;