Component runtime optimization



  • Hello,

    does using Loaders decrease the runtime needed to create a custom Component?
    MyComponent.qml
    Without Loader:
    @import QtQuick 2.2

    MouseArea {
    width: 72
    height: 72
    Rectangle {
    anchors.fill: parent
    color: "green"
    Column {
    Text {
    text: "Test text"
    }
    ...
    }
    }
    }@
    With Loaders:
    @import QtQuick 2.2

    MouseArea {
    width: 72
    height: 72
    property Component __text: Text {
    text: "Test text"
    }
    Rectangle {
    anchors.fill: parent
    color: "green"
    Column {
    Loader {
    sourceComponent: __text
    }
    ...
    }
    }
    }@





  • Do you need the text on startup ?



  • [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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.