1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
29 \page qdeclarativeperformance.html
30 \inqmlmodule QtQuick 1
31 \title QML Performance - Qt Quick 1
33 \section1 Opaque Items
35 Items hidden behind an opaque item incur a cost. If an item will be enitrely
36 obscured by an opaque item, set its opacity to 0. One common example of
37 this is when a "details" page is shown over the main application view.
41 \e clip is set to false by default. Enable clipping only when necessary.
43 \section1 Anchors vs. Binding
45 It is more efficient to use anchors rather than bindings to position items
46 relative to each other. Consider this use of bindings to position rect2
53 width: 200; height: 200
58 y: rect1.y + rect1.height
59 width: rect1.width - 20
64 This is achieved more efficiently using anchors:
70 width: 200; height: 200
75 anchors.left: rect1.left
76 anchors.top: rect1.bottom
77 anchors.right: rect1.right
78 anchors.rightMargin: 20
84 Images consume a great deal of memory and may also be costly to load. In order
85 to deal with large images efficiently it is recommended that the Image::sourceSize
86 property be set to a size no greater than that necessary to render it. Beware that
87 changing the sourceSize will cause the image to be reloaded.
89 Images on the local filesystem are usually loaded synchronously. This is usually
90 the desired behavior for user interface elements, however for large images that
91 do not necessarily need to be visible immediately, set the Image::asynchronous
92 property to true. This will load the image in a low priority thread.
94 \section1 View Delegates
96 Delegates must be created quickly as the view is flicked. There are two important
97 aspects to maintaining a smooth view:
100 \o Small delegates - keep the amount of QML to a minimum. Have just enough
101 QML in the delegate to display the necessary information. Any additional functionality
102 that is only needed when the delegate is clicked, for example, should be created by
104 \o Fast data access - ensure the data model is as fast as possible.
107 \section1 Image resources over composition
109 If possible, provide a single image resource, rather than using composition
110 of a number of elements. For example, a frame with a shadow could be created using
111 a Rectangle placed over an Image providing the shadow. It is more efficient to
112 provide an image that includes the frame and the shadow.
114 \section1 Limit JavaScript
116 Avoid running JavaScript during animation. For example, running a complex
117 JavaScript expression for each frame of an x property animation.
121 Often using a different graphics system will give superior performance to the native
122 graphics system (this is especially the case on X11). This can be configured using
123 QApplication::setGraphicsSystem() or via the command line using the \c -graphicssystem
126 You can enable OpenGL acceleration using the \c opengl graphics system, or by setting a
127 QGLWidget as the viewport of your QDeclarativeView.
129 You may need to try various options to find what works the best for your application.
130 For embedded X11-based devices one recommended combination is to use the raster graphics
131 system with a QGLWidget for the viewport. While this doesn't guarantee the \bold fastest
132 performance for all use-cases, it typically has \bold{consistently good} performance for
133 all use-cases. In contrast, only using the raster paint engine may result in very good
134 performance for parts of your application and very poor performance elsewhere.
136 The QML Viewer uses the raster graphics system by default for X11 and OS X. It also
137 includes a \c -opengl command line option which sets a QGLWidget as the viewport of the
138 view. On OS X, a QGLWidget is always used.
140 You can also prevent QDeclarativeView from painting its window background if
141 you will provide the background of your application using QML, e.g.
144 QDeclarativeView window;
145 window.setAttribute(Qt::WA_OpaquePaintEvent);
146 window.setAttribute(Qt::WA_NoSystemBackground);
147 window.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
148 window.viewport()->setAttribute(Qt::WA_NoSystemBackground);