Component runtime optimization
-
wrote on 21 Mar 2014, 11:16 last edited by
Hello,
does using Loaders decrease the runtime needed to create a custom Component?
MyComponent.qml
Without Loader:
@import QtQuick 2.2MouseArea {
width: 72
height: 72
Rectangle {
anchors.fill: parent
color: "green"
Column {
Text {
text: "Test text"
}
...
}
}
}@
With Loaders:
@import QtQuick 2.2MouseArea {
width: 72
height: 72
property Component __text: Text {
text: "Test text"
}
Rectangle {
anchors.fill: parent
color: "green"
Column {
Loader {
sourceComponent: __text
}
...
}
}
}@ -
wrote on 23 Mar 2014, 10:43 last edited by
Did you try "QML Profiler?":http://doc-snapshot.qt-project.org/qtcreator-3.0/creator-qml-performance-monitor.html
-
wrote on 13 Apr 2014, 11:11 last edited by
Do you need the text on startup ?
-
wrote on 14 Apr 2014, 08:32 last edited by
[quote author="aabc" date="1397387516"]Do you need the text on startup ?[/quote]
In that case i do need the text at startup. In such a case i will create them without a loader, but it is also posible to create it with a loader and add a splash-screen which is visible while !Loader.Ready. -
wrote on 14 Apr 2014, 13:46 last edited by
I think this change by itself is not very useful. Note that Loader is by default synchronous meaning it will block until the item it loads has completed. This is usually wanted behaviour because otherwise you will see it pop into existence after the initial window has been shown. In reality this means that the snippet above would be slower than not using a Loader because you are simply constructing and adding yet another item to the scene.
You can set the asynchronous property to false on your Loader which might speed up the initial show but hardly noticeable for this particular use case. You should probably refrain from using Loader unless it is a fairly complex component you are creating as the Loader itself might be as expensive to create as a basic Text item itself.