forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Thomas Hartmann
parent
b70370281c
commit
5464d60728
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user