diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-26 12:02:03 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-31 17:08:46 +0000 |
commit | 2312f5a2b4fd775933f54c9d8435ea047de2310a (patch) | |
tree | 77c5c5f7547846c371a4a99b2fac48100f0d6b3b /src/qml/compiler/qqmlirbuilder.cpp | |
parent | 193db4c52613a37275535783825190ddd7e1f758 (diff) |
Reduce memory usage caused by strings with AOT cache files
For AOT loaded cache files, the CompiledData::Unit we produce is
ephemeral by design. That same applies to the strings, where we don't
really need to write out a new string table but we might as well just
keep the QStringList around. That avoids copying all the string data and
saves another 21K RAM with the gallery. It might even save a little more
if some of the new strings are truly shared via implicit QString
sharing. Also their "extraction" via stringAt(index) becomes as fast as
for the strings that come from mmap'ed memory - with no copying
involved.
Task-number: QTBUG-69588
Change-Id: I06cf0f083e3b8d3c5dbabb22beb0711f88fc8692
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index e2ea8f6853..293d6d2655 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1575,6 +1575,13 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen // No more new strings after this point, we're calculating offsets. output.jsGenerator.stringTable.freeze(); + const bool writeStringTable = +#ifndef V4_BOOTSTRAP + output.javaScriptCompilationUnit->backingUnit == nullptr; +#else + true; +#endif + const int importSize = sizeof(QV4::CompiledData::Import) * output.imports.count(); const int objectOffsetTableSize = output.objects.count() * sizeof(quint32); @@ -1598,7 +1605,7 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen objectsSize += enumTableSize; } - const int totalSize = jsUnitSize + importSize + objectOffsetTableSize + objectsSize + output.jsGenerator.stringTable.sizeOfTableAndData(); + const int totalSize = jsUnitSize + importSize + objectOffsetTableSize + objectsSize + (writeStringTable ? output.jsGenerator.stringTable.sizeOfTableAndData() : 0); char *data = (char*)malloc(totalSize); memcpy(data, jsUnit, jsUnitSize); memset(data + jsUnitSize, 0, totalSize - jsUnitSize); @@ -1614,8 +1621,13 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen qmlUnit->nImports = output.imports.count(); qmlUnit->offsetToObjects = jsUnitSize + importSize; qmlUnit->nObjects = output.objects.count(); - qmlUnit->offsetToStringTable = totalSize - output.jsGenerator.stringTable.sizeOfTableAndData(); - qmlUnit->stringTableSize = output.jsGenerator.stringTable.stringCount(); + if (writeStringTable) { + qmlUnit->offsetToStringTable = totalSize - output.jsGenerator.stringTable.sizeOfTableAndData(); + qmlUnit->stringTableSize = output.jsGenerator.stringTable.stringCount(); + } else { + qmlUnit->offsetToStringTable = 0; + qmlUnit->stringTableSize = 0; + } qmlUnit->sourceFileIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.fileName); qmlUnit->finalUrlIndex = output.jsGenerator.stringTable.getStringId(output.jsModule.finalUrl); @@ -1772,7 +1784,12 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen } } - output.jsGenerator.stringTable.serialize(qmlUnit); + if (writeStringTable) + output.jsGenerator.stringTable.serialize(qmlUnit); +#ifndef V4_BOOTSTRAP + else + output.javaScriptCompilationUnit->dynamicStrings = output.jsGenerator.stringTable.allStrings(); +#endif qmlUnit->generateChecksum(); |