From e3ed4eda44f2a6d2b80ddac7efca92b8297b524f Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 6 Jun 2024 15:30:11 +0000 Subject: [PATCH] Fix lag on dragging mod list in Launcher on Android Tested by enabling dragging on desktop. According to profiler, most of time was spent on generating mod information. Cheap to do once, but it looks like Qt does this A LOT. Added simple caching & reduced copying. Seems to be working fine on PC, but not yet confirmed whether same goes for mobile --- launcher/modManager/cmodlist.cpp | 23 +++++++++++++++++++++-- launcher/modManager/cmodlist.h | 5 ++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/launcher/modManager/cmodlist.cpp b/launcher/modManager/cmodlist.cpp index 304ec1551..fad621601 100644 --- a/launcher/modManager/cmodlist.cpp +++ b/launcher/modManager/cmodlist.cpp @@ -226,11 +226,13 @@ QVariantMap CModList::copyField(QVariantMap data, QString from, QString to) cons void CModList::reloadRepositories() { + cachedMods.clear(); } void CModList::resetRepositories() { repositories.clear(); + cachedMods.clear(); } void CModList::addRepository(QVariantMap data) @@ -238,20 +240,25 @@ void CModList::addRepository(QVariantMap data) for(auto & key : data.keys()) data[key.toLower()] = data.take(key); repositories.push_back(copyField(data, "version", "latestVersion")); + + cachedMods.clear(); } void CModList::setLocalModList(QVariantMap data) { localModList = copyField(data, "version", "installedVersion"); + cachedMods.clear(); } void CModList::setModSettings(QVariant data) { modSettings = data.toMap(); + cachedMods.clear(); } void CModList::modChanged(QString modID) { + cachedMods.clear(); } static QVariant getValue(QVariant input, QString path) @@ -270,9 +277,21 @@ static QVariant getValue(QVariant input, QString path) } } -CModEntry CModList::getMod(QString modname) const +const CModEntry & CModList::getMod(QString modName) const +{ + modName = modName.toLower(); + + auto it = cachedMods.find(modName); + + if (it != cachedMods.end()) + return it.value(); + + auto itNew = cachedMods.insert(modName, getModUncached(modName)); + return *itNew; +} + +CModEntry CModList::getModUncached(QString modname) const { - modname = modname.toLower(); QVariantMap repo; QVariantMap local = localModList[modname].toMap(); QVariantMap settings; diff --git a/launcher/modManager/cmodlist.h b/launcher/modManager/cmodlist.h index 54232872b..1adf9e5b6 100644 --- a/launcher/modManager/cmodlist.h +++ b/launcher/modManager/cmodlist.h @@ -82,8 +82,11 @@ class CModList QVariantMap localModList; QVariantMap modSettings; + mutable QMap cachedMods; + QVariantMap copyField(QVariantMap data, QString from, QString to) const; + CModEntry getModUncached(QString modname) const; public: virtual void resetRepositories(); virtual void reloadRepositories(); @@ -93,7 +96,7 @@ public: virtual void modChanged(QString modID); // returns mod by name. Note: mod MUST exist - CModEntry getMod(QString modname) const; + const CModEntry & getMod(QString modname) const; // returns list of all mods necessary to run selected one, including mod itself // order is: first mods in list don't have any dependencies, last mod is modname