From 8237f645a33199e0a8aded0a3f7e6077990707fd Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 23 Jul 2018 14:08:06 +0200 Subject: Optimize memory consumption of ahead-of-time compile cache files When loading a pre-compiled cache file, the strings contained therein will remain available in memory since commit 7dcada48d2435e8ceb0cc8a6771f79b76979e11f. While for aot built cache files we may have to add new strings (for example for signal handler parameters), we can re-use the existing strings by omitting them from the intermediately created string table. This saves ~283K RAM with qtquickcontrols1 gallery. Task-number: QTBUG-69588 Change-Id: I8ea807f6dea4cc35d8b7e5f7329809ed1cd12880 Reviewed-by: Lars Knoll --- src/qml/compiler/qv4compiler.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/qml/compiler/qv4compiler.cpp') diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 6dbd4a35fb..bc7265ab0c 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -77,13 +77,23 @@ void QV4::Compiler::StringTableGenerator::clear() stringDataSize = 0; } +void QV4::Compiler::StringTableGenerator::initializeFromBackingUnit(const QV4::CompiledData::Unit *unit) +{ + clear(); + for (uint i = 0; i < unit->stringTableSize; ++i) + registerString(unit->stringAtInternal(i)); + backingUnitTableSize = unit->stringTableSize; + stringDataSize = 0; +} + void QV4::Compiler::StringTableGenerator::serialize(CompiledData::Unit *unit) { char *dataStart = reinterpret_cast(unit); quint32_le *stringTable = reinterpret_cast(dataStart + unit->offsetToStringTable); char *stringData = dataStart + unit->offsetToStringTable + unit->stringTableSize * sizeof(uint); - for (int i = 0; i < strings.size(); ++i) { - stringTable[i] = stringData - dataStart; + for (int i = backingUnitTableSize ; i < strings.size(); ++i) { + const int index = i - backingUnitTableSize; + stringTable[index] = stringData - dataStart; const QString &qstr = strings.at(i); QV4::CompiledData::String *s = reinterpret_cast(stringData); -- cgit v1.2.3