Performance tip QML other: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(removed the paragraph on the two ways to do anchoring - that is purely syntactical and has no memory impact. if it would have, please add a reference to a measurement and/or explanation why that would be the case.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Fixed length lists with Flickable+Column+Repeater==
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 
[[Category:Developing_with_Qt::Qt Quick]]
[[Category:Developing_with_Qt::Performance Tips]]
 
 
== Fixed length lists with Flickable+Column+Repeater ==
 
 
 
If you have a simple list with fixed length, you could try to optimize performance using Flickable+Column+Repeater instead of QML ListView. This way list creation would be slower, but list scrolling smoother.
 
 
 
== Animate as small area of the screen as possible in transition animations ==


If you have a simple list with fixed length, you could try to optimize performance using Flickable+Column+Repeater instead of <span class="caps">QML</span> ListView. This way list creation would be slower, but list scrolling smoother.


==Animate as small area of the screen as possible in transition animations==


If you need to move 3 elements in a second try moving each at a time in 300ms. The system works so that it calculates the bounds of items that need repainting and paints everything inside those bounds. This can be really bad two little things are animating in opposite corners.
If you need to move 3 elements in a second try moving each at a time in 300ms. The system works so that it calculates the bounds of items that need repainting and paints everything inside those bounds. This can be really bad two little things are animating in opposite corners.


==Avoid complex clipping==
 
 
== Avoid complex clipping ==
 
 


You should enable clipping only when you really need it. The default clip value is false.
You should enable clipping only when you really need it. The default clip value is false.


* If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle
* If clipping is enabled, an item will clip its own painting, as well as the painting of its children, to its bounding rectangle
* More info on Item.clip: http://doc.qt.nokia.com/latest/qml-item.html#clip-prop
* More info on Item.clip: http://doc.qt.nokia.com/latest/qml-item.html#clip-prop


==Does it help performance if you strip off comments or white space from <span class="caps">QML</span> files?==
== Does it help performance if you strip off comments or white space from QML files? ==
 


Not really. The files are reprocessed into a binary in-memory representation at startup, so by runtime there should be no performance difference. You might be lucky and get 0.5% improvement, and then only on start-up (where <span class="caps">QML</span> parsing is done), nowhere else.


==Avoid unnecessary conversion==
Not really. The files are reprocessed into a binary in-memory representation at startup, so by runtime there should be no performance difference. You might be lucky and get 0.5% improvement, and then only on start-up (where QML parsing is done), nowhere else.


<span class="caps">QML</span> performs a type conversion if the given value for a property does not match with the type specified for the property. This conversion consumes additional memory.


* For example, =Image= and =BorderImage= have a source, which is of type =url=. Conversion is needed if image source’s property is defined as =string=, it should rather be =property url=.


* Wrong way:<br />
== Avoid unnecessary conversion ==


* Right way:<br />


==Anchors and memory consumption==


Anchoring can be done in two ways:
QML performs a type conversion if the given value for a property does not match with the type specified for the property. This conversion consumes additional memory.


* The normal way:<br />


* This way consumes slightly less memory:<br />


==Beware of string operations==
* For example, =Image= and =BorderImage= have a source, which is of type =url=. Conversion is needed if image source's property is defined as =string=, it should rather be =property url=.


* Multiple uses of the ‘+’ operator usually means multiple memory allocations
* Wrong way:
* Use !StringBuilder for more efficient strings. !QStringBuilder uses expression templates and reimplements the ‘‘ operator so that when you use ‘’ for string concatenation instead of ‘+’, multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.
<code>
* Define: QT_USE_FAST_CONCATENATION, QT_USE_FAST_OPERATOR_PLUS
property string messageAvatar: ""
* See more: http://doc.trolltech.com/latest/qstring.html#more-efficient-string-construction
</code>


===Categories:===
* Right way:
<code>
property url messageAvatar: ""
</code>
== Beware of string operations ==


* [[:Category:Developing with Qt|Developing_with_Qt]]
* Multiple uses of the '''' operator usually means multiple memory allocations
** [[:Category:Developing with Qt::Performance Tips|Performance_Tips]]
* Use [[Image:StringBuilder for more efficient strings. |StringBuilder for more efficient strings. ]]QStringBuilder uses expression templates and reimplements the '' operator so that when you use '' for string concatenation instead of '''', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.
* [[:Category:Developing with Qt::Qt Quick|Qt_Quick]]
* Define: QT_USE_FAST_CONCATENATION, QT_USE_FAST_OPERATOR_PLUS

Latest revision as of 10:14, 8 July 2016

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.


Fixed length lists with Flickable+Column+Repeater

If you have a simple list with fixed length, you could try to optimize performance using Flickable+Column+Repeater instead of QML ListView. This way list creation would be slower, but list scrolling smoother.


Animate as small area of the screen as possible in transition animations

If you need to move 3 elements in a second try moving each at a time in 300ms. The system works so that it calculates the bounds of items that need repainting and paints everything inside those bounds. This can be really bad two little things are animating in opposite corners.


Avoid complex clipping

You should enable clipping only when you really need it. The default clip value is false.


Does it help performance if you strip off comments or white space from QML files?

Not really. The files are reprocessed into a binary in-memory representation at startup, so by runtime there should be no performance difference. You might be lucky and get 0.5% improvement, and then only on start-up (where QML parsing is done), nowhere else.


Avoid unnecessary conversion

QML performs a type conversion if the given value for a property does not match with the type specified for the property. This conversion consumes additional memory.


  • For example, =Image= and =BorderImage= have a source, which is of type =url=. Conversion is needed if image source's property is defined as =string=, it should rather be =property url=.
  • Wrong way:
property string messageAvatar: ""
  • Right way:
property url messageAvatar: ""

Beware of string operations

  • Multiple uses of the ' operator usually means multiple memory allocations
  • Use StringBuilder for more efficient strings.QStringBuilder uses expression templates and reimplements the operator so that when you use for string concatenation instead of ', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.
  • Define: QT_USE_FAST_CONCATENATION, QT_USE_FAST_OPERATOR_PLUS