aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-20 16:37:28 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-31 12:01:04 +0000
commitf70a25aecb2415d33b76b95d607f7e303c8db0a0 (patch)
tree730986269a163158420eedb0b5c464047e316ab1 /tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
parent41076956f7d38d9c661ae97111af9834786efa24 (diff)
Reduce memory usage when loading QML files from AOT generated caches
When we have to modify the string table, we should make sure to discard the old one for the new CompiledData::Unit we hold in memory. This also allows discarding the old QML tables as they'll be rewritten anyway. Saves about ~402K RAM with qtquickcontrols1 gallery. Task-number: QTBUG-69588 Change-Id: Iae3e9fe2578ea8cb7ec1859ce660f75cfb388dee Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp')
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index c9e831a6c1..fab33a4175 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -236,12 +236,37 @@ void tst_qmlcachegen::signalHandlerParameters()
QVERIFY(QFile::exists(cacheFilePath));
QVERIFY(QFile::remove(testFilePath));
+ quint32 oldImportsOffset = 0;
+ {
+ QFile cache(cacheFilePath);
+ QVERIFY(cache.open(QIODevice::ReadOnly));
+ const QV4::CompiledData::Unit *cacheUnit = reinterpret_cast<const QV4::CompiledData::Unit *>(cache.map(/*offset*/0, sizeof(QV4::CompiledData::Unit)));
+ QVERIFY(cacheUnit);
+ oldImportsOffset = cacheUnit->offsetToImports;
+ }
+
QQmlEngine engine;
CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(testFilePath));
QScopedPointer<QObject> obj(component.create());
QVERIFY(!obj.isNull());
QMetaObject::invokeMethod(obj.data(), "runTest");
QCOMPARE(obj->property("result").toInt(), 42);
+
+ {
+ auto componentPrivate = QQmlComponentPrivate::get(&component);
+ QVERIFY(componentPrivate);
+ auto compilationUnit = componentPrivate->compilationUnit;
+ QVERIFY(compilationUnit);
+ QVERIFY(compilationUnit->unitData());
+
+ // The determination of the signal parameters for onTestMe by extending the
+ // formals of the CompiledData::Function of the signal handler implies adding new
+ // strings to the compilation unit. That means discarding the old string table as well as QML
+ // fields (to be newly written) to save memory. That means the first QML specific table
+ // (offsetToImports) should be the same _plus_ one entry in the newly added formals table.
+ const quint32 sizeOfNewFormalsTable = 1 * sizeof(quint32);
+ QCOMPARE(quint32(compilationUnit->unitData()->offsetToImports), oldImportsOffset + sizeOfNewFormalsTable);
+ }
}
void tst_qmlcachegen::errorOnArgumentsInSignalHandler()