diff options
| author | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-20 16:37:28 +0200 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-31 12:01:04 +0000 |
| commit | f70a25aecb2415d33b76b95d607f7e303c8db0a0 (patch) | |
| tree | 730986269a163158420eedb0b5c464047e316ab1 /src/qml/compiler/qv4compileddata.cpp | |
| parent | 41076956f7d38d9c661ae97111af9834786efa24 (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 'src/qml/compiler/qv4compileddata.cpp')
| -rw-r--r-- | src/qml/compiler/qv4compileddata.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index 357c6fc04a..d9e58bb6e8 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -471,15 +471,18 @@ Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument) QV4::CompiledData::Unit *jsUnit = const_cast<QV4::CompiledData::Unit*>(compilationUnit->data); auto ensureWritableUnit = [&jsUnit, &compilationUnit]() { if (jsUnit == compilationUnit->data) { - char *unitCopy = (char*)malloc(jsUnit->unitSize); - memcpy(unitCopy, jsUnit, jsUnit->unitSize); + // Discard the old QML tables as the caller will re-create them anyway. + quint32 unitSizeWithoutQMLTables = jsUnit->offsetToImports; + char *unitCopy = (char*)malloc(unitSizeWithoutQMLTables); + memcpy(unitCopy, jsUnit, unitSizeWithoutQMLTables); jsUnit = reinterpret_cast<QV4::CompiledData::Unit*>(unitCopy); + jsUnit->unitSize = unitSizeWithoutQMLTables; } }; QV4::Compiler::StringTableGenerator &stringTable = irDocument->jsGenerator.stringTable; - if (jsUnit->sourceFileIndex == quint32(0) || jsUnit->stringAt(jsUnit->sourceFileIndex) != irDocument->jsModule.fileName) { + if (jsUnit->sourceFileIndex == quint32(0) || stringTable.stringForIndex(jsUnit->sourceFileIndex) != irDocument->jsModule.fileName) { ensureWritableUnit(); jsUnit->sourceFileIndex = stringTable.registerString(irDocument->jsModule.fileName); jsUnit->finalUrlIndex = stringTable.registerString(irDocument->jsModule.finalUrl); @@ -522,11 +525,7 @@ Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument) // Update signal signatures if (!changedSignals.isEmpty()) { - if (jsUnit == compilationUnit->data) { - char *unitCopy = (char*)malloc(jsUnit->unitSize); - memcpy(unitCopy, jsUnit, jsUnit->unitSize); - jsUnit = reinterpret_cast<QV4::CompiledData::Unit*>(unitCopy); - } + ensureWritableUnit(); for (int i = 0; i < changedSignals.count(); ++i) { const uint functionIndex = changedSignals.at(i); |
