source: trunk/doc/src/declarative/qdeclarativeperformance.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 4.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29\page qdeclarativeperformance.html
30\title QML Performance
31
32\section1 Opaque Items
33
34Items hidden behind an opaque item incur a cost. If an item will be enitrely
35obscured by an opaque item, set its opacity to 0. One common example of
36this is when a "details" page is shown over the main application view.
37
38\section1 Clipping
39
40\e clip is set to false by default. Enable clipping only when necessary.
41
42\section1 Anchors vs. Binding
43
44It is more efficient to use anchors rather than bindings to position items
45relative to each other. Consider this use of bindings to position rect2
46relative to rect1:
47
48\code
49Rectangle {
50 id: rect1
51 x: 20
52 width: 200; height: 200
53}
54Rectangle {
55 id: rect2
56 x: rect1.x
57 y: rect1.y + rect1.height
58 width: rect1.width - 20
59 height: 200
60}
61\endcode
62
63This is achieved more efficiently using anchors:
64
65\code
66Rectangle {
67 id: rect1
68 x: 20
69 width: 200; height: 200
70}
71Rectangle {
72 id: rect2
73 height: 200
74 anchors.left: rect1.left
75 anchors.top: rect1.bottom
76 anchors.right: rect1.right
77 anchors.rightMargin: 20
78}
79\endcode
80
81\section1 Images
82
83Images consume a great deal of memory and may also be costly to load. In order
84to deal with large images efficiently it is recommended that the Image::sourceSize
85property be set to a size no greater than that necessary to render it. Beware that
86changing the sourceSize will cause the image to be reloaded.
87
88Images on the local filesystem are usually loaded synchronously. This is usually
89the desired behavior for user interface elements, however for large images that
90do not necessarily need to be visible immediately, set the Image::asynchronous
91property to true. This will load the image in a low priority thread.
92
93\section1 View Delegates
94
95Delegates must be created quickly as the view is flicked. There are two important
96aspects to maintaining a smooth view:
97
98\list
99\o Small delegates - keep the amount of QML to a minimum. Have just enough
100QML in the delegate to display the necessary information. Any additional functionality
101that is only needed when the delegate is clicked, for example, should be created by
102a Loader as needed.
103\o Fast data access - ensure the data model is as fast as possible.
104\endlist
105
106\section1 Image resources over composition
107
108If possible, provide a single image resource, rather than using composition
109of a number of elements. For example, a frame with a shadow could be created using
110a Rectangle placed over an Image providing the shadow. It is more efficient to
111provide an image that includes the frame and the shadow.
112
113\section1 Limit JavaScript
114
115Avoid running JavaScript during animation. For example, running a complex
116JavaScript expression for each frame of an x property animation.
117
118\section1 Rendering
119
120Often using a different graphics system will give superior performance to the native
121graphics system (this is especially the case on X11). This can be configured using
122QApplication::setGraphicsSystem() or via the command line using the \c -graphicssystem
123switch.
124
125You can enable OpenGL acceleration using the \c opengl graphics system, or by setting a
126QGLWidget as the viewport of your QDeclarativeView.
127
128You may need to try various options to find what works the best for your application.
129For embedded X11-based devices one recommended combination is to use the raster graphics
130system with a QGLWidget for the viewport. While this doesn't guarantee the \bold fastest
131performance for all use-cases, it typically has \bold{consistently good} performance for
132all use-cases. In contrast, only using the raster paint engine may result in very good
133performance for parts of your application and very poor performance elsewhere.
134
135The QML Viewer uses the raster graphics system by default for X11 and OS X. It also
136includes a \c -opengl command line option which sets a QGLWidget as the viewport of the
137view. On OS X, a QGLWidget is always used.
138
139*/
Note: See TracBrowser for help on using the repository browser.