'QML creating Text element takes long time
I noticed that creating Text element in QML takes long time.
For an example:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 320
height: 640
color: "yellow"
ListView {
anchors.fill: parent
model: 1000
delegate: Component {
Rectangle {
width: parent.width
height: 50
color: index % 2 == 0 ? "#eee" : "#ddd"
Text {
anchors.fill: parent
font { family: "Helvetica"; pixelSize: 15 }
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
text: "9"
}
}
}
}
}
In QML Profiler this is result:
Location Type Time in Percent Total Time Calls Mean Time Median Time Longest Time Shortest Time Details
<program> 100.00 % 730.664 ms 1 730.664 ms 730.664 ms 730.664 ms 730.664 ms Main Program
main.qml:17 Create 82.33 % 601.544 ms 706 852.045 µs 46.227 µs 536.645 ms 7.777 µs QtQuick/Text
main.qml:9 Create 76.37 % 557.974 ms 2 278.987 ms 557.793 ms 557.793 ms 181.747 µs QtQuick/ListView
main.qml:4 Create 15.04 % 109.901 ms 2 54.951 ms 109.520 ms 109.520 ms 380.668 µs QtQuick.Window/Window
main.qml:13 Create 4.90 % 35.826 ms 706 50.744 µs 14.842 µs 20.833 ms 0.438 µs QtQuick/Rectangle
main.qml:18 Binding 0.74 % 5.397 ms 353 15.288 µs 15.704 µs 86.770 µs 4.841 µs anchors.fill: parent
main.qml:16 Binding 0.58 % 4.224 ms 353 11.964 µs 11.686 µs 171.614 µs 4.813 µs color: index % 2 == 0 ? "#eee" : "#ddd"
main.qml:18 JavaScript 0.40 % 2.952 ms 353 8.361 µs 8.689 µs 22.030 µs 2.597 µs expression for fill
main.qml:16 JavaScript 0.32 % 2.351 ms 353 6.660 µs 6.289 µs 165.754 µs 2.598 µs expression for color
main.qml:14 Binding 0.26 % 1.870 ms 354 5.282 µs 5.301 µs 31.643 µs 2.261 µs width: parent.width
main.qml:14 JavaScript 0.19 % 1.419 ms 354 4.007 µs 4.066 µs 12.325 µs 1.591 µs expression for width
main.qml:1 Compile 0.10 % 759.314 µs 1 759.314 µs 759.314 µs 759.314 µs 759.314 µs main.qml
main.qml:10 Binding 0.01 % 41.470 µs 1 41.470 µs 41.470 µs 41.470 µs 41.470 µs anchors.fill: parent
main.qml:10 JavaScript 0.00 % 22.325 µs 1 22.325 µs 22.325 µs 22.325 µs 22.325 µs expression for fill
main.qml:12 Create 0.00 % 3.321 µs 1 3.321 µs 3.321 µs 3.321 µs 3.321 µs <component>
As you can see, creating Text element takes very high time.
In another project with some Text in delegate, this is the result:
Location Type Time in Percent Total Time Calls Mean Time Median Time Longest Time Shortest Time Details
PostLikeAndMark.qml:41 Create 79.20 % 1.261 s 46 27.406 ms 60.427 µs 1.257 s 7.124 µs QtQuick/Text
Is there any solution to work around this problem?
UPDATE
It seems that this problem might be related to font family in some situations.
For a new recent project, I found that using some font families introduces this problem. (Segue UI
)
Changing font family to some other fonts such as Myriad Pro
, solved the problem.
Solution 1:[1]
I found, that by setting the textFormat property where possible, a relevant increase of overall performance could be achieved. Depends on your implementation of course.
Got the hint from: https://doc.qt.io/qt-5/qtquick-performance.html#text-elements
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nico |