aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2023-06-09 16:08:34 +0300
committerThomas Hartmann <thomas.hartmann@qt.io>2023-06-13 10:22:23 +0000
commit5464d607282e556006f0331c6dbb22c095a39871 (patch)
treecc2ade0d33e67b10cd5e3eb4a6629ff7abe4ffdb
parentb70370281cd7cadbdbf99f6da2753f07fe67a083 (diff)
QmlDesigner: Delete puppet rhi pipeline cache every now and then
Unused pipelines are never removed from the cache, so if we don't delete it ourselves, the cache file will keep growing indefinitely. We now keep count of how many times we have stored the cache and remove it after set number of times to avoid bloat. Fixes: QDS-10075 Change-Id: I5a4d25a7e40c8ff761c6c523cb80cda3f721528f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> (cherry picked from commit 07d0cfa1e2b5ae0d53e4a8ec3642b933928fe365) Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/tools/qml2puppet/qml2puppet/instances/qt5nodeinstanceserver.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5nodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5nodeinstanceserver.cpp
index e5cda87789..a696fd45ce 100644
--- a/src/tools/qml2puppet/qml2puppet/instances/qt5nodeinstanceserver.cpp
+++ b/src/tools/qml2puppet/qml2puppet/instances/qt5nodeinstanceserver.cpp
@@ -217,18 +217,34 @@ void Qt5NodeInstanceServer::savePipelineCacheData()
if (!m_viewData.rhi)
return;
- const QByteArray pipelineData = m_viewData.rhi->pipelineCacheData();
+ QByteArray pipelineData = m_viewData.rhi->pipelineCacheData();
if (pipelineData.isEmpty())
return;
- m_pipelineCacheData = pipelineData;
+ char count = 0;
+ if (!m_pipelineCacheData.isEmpty())
+ count = m_pipelineCacheData[m_pipelineCacheData.size() - 1];
+ pipelineData.append(++count);
- QTimer::singleShot(0, this, [this]() {
- QFile file(m_pipelineCacheFile);
- if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
- file.write(m_pipelineCacheData);
- });
+ const bool needWrite = m_pipelineCacheData.size() != pipelineData.size()
+ && !m_pipelineCacheFile.isEmpty();
+
+ if (needWrite) {
+ m_pipelineCacheData = pipelineData;
+
+ QTimer::singleShot(0, this, [this]() {
+ QFile cacheFile(m_pipelineCacheFile);
+
+ // Cache file can grow indefinitely, so let's just purge it every so often.
+ // The count is stored as the last char in the data.
+ char count = m_pipelineCacheData[m_pipelineCacheData.size() - 1];
+ if (count > 25)
+ cacheFile.remove();
+ else if (cacheFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
+ cacheFile.write(m_pipelineCacheData);
+ });
+ }
#endif
}
@@ -267,7 +283,7 @@ bool Qt5NodeInstanceServer::initRhi([[maybe_unused]] RenderViewData &viewData)
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 1)
if (!m_pipelineCacheData.isEmpty())
- viewData.rhi->setPipelineCacheData(m_pipelineCacheData);
+ viewData.rhi->setPipelineCacheData(m_pipelineCacheData.left(m_pipelineCacheData.size() - 1));
#endif
}