Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Memory Consumption of active QQmlQuickWidget nested in QWidget is vastly higher than inactive QQmlQuickWidget (4900 MB vs. 200 MB)
Eth3real last edited by Eth3real
I am developing a research prototype for a novel interaction concept and computational desktop environment, I currently call Sketchable Interaction (SI).
Currently, SI works only on Debian-based linuxes.
In a nutshell, SI allows users to draw interactive regions on their desktop which carry effects.
Once two or more regions overlap, regions which's effects are compatible to each other apply their effects to each other as well.
In this way, graphical representations and data of files, etc. can be set, modified or deleted.
Here are some screenshots to give a visual example:
Showing Desktop Environment.
Drawing region (blue one) for Opening Folders/Files.
Opended Desktop-Folder by overlapping it with the blue region and drew a Preview File region.
Moved image file (png) with the cat out of the folder.
Overlapped image file with the cat with the green region to show a preview of the image.
Here's the link to the SI repositories on github: https://github.com/PDA-UR/Sketchable-Interaction and https://github.com/PDA-UR/Sketchable-Interaction-Plugins
Technical Status Quo of SI
SI is written in C++ with the current Qt5 and QML versions.
SI-Plugins which represent the effects you saw in the screenshots, are written in python3.7+, with the use of Boost.Python and do not use PyQt5.
SI opens a MainWindow and every region drawing (everything you see in the screenshots is a region, including the mouse cursor) is a QWidget which is a borderless child of that MainWindow.
In order to do any styling e.g. display textures, like the folder icon, SI uses QML files, represented as QQuickWidgets wich is a borderless child of that QWidget (I am aware of the stacking order problem, but we can ignore that for this question!)
I am able to change QML styling from within SI-Python-Plugins at runtime.
This internally uses QMetaObject to pass a QMap<qstr, QVariant> to a function in the container component.
QMetaObject::invokeMethod(reinterpret_cast<QObject *>(d_view->rootObject()), "updateData", QGenericReturnArgument(), Q_ARG(QVariant, region->data()));
I tested this with signals/slots as well, yet was unable to get it working as I intended, the above method does work as intended.
Apparently, this is due to initializing exactly one QQmlEngine, instead of one per QQuickWidget.
This single QQmlEngine has CppOwnership.
engine = new QQmlEngine(this); engine->setObjectOwnership(engine, QQmlEngine::CppOwnership);
For testing purposes and performance benchmarking I intend to spawn thousands of regions:
The following screenshots shows 1009 regions (1000 in the center).
This one is with all QML related code deactivated:
This yields, according to the tool htop, roughly 200 MB memory consumption.
The same example with QML activated:
This yields roughly 4900 MB memory consumption.
The texture used in the yellow regions in the example with QML is a 64x64 px 32-bit RGBA image.
This memory difference really strikes me as odd.
The memory required for all images equals 1000 (number of regions) * 64 * 64 (number of pixels) * 4 (number of bytes if 4 channels with 8 bit) = 16,384,000 bytes which are ~16.5 MB. Of course there should be some further overhead per image, yet not 4.8 GB of overhead.
I found out via other questions here or other sources that QML apparently needs a lot memory (some call it a memory hog).
Yet, this high difference could stem from my unorthodox usage of Qt5 and QML.
Is there a way to lower this memory consumption, given the current state of the SI software?
Are their alternative approaches I did not come up with?
Is their a flag in Qt5/QML docs I missed which trivializes the problem?
Sorry for the lengthy post and thanks in advance for your help.
Edits: Typos, Clarity