~ps-jenkins/autopilot/latestsnapshot-1.2daily13.04.09-0ubuntu1

« back to all changes in this revision

Viewing changes to docs/faq/faq.rst

  • Committer: Tarmac
  • Author(s): Michael Zanetti
  • Date: 2013-03-25 22:55:08 UTC
  • mfrom: (98.3.6 autopilot)
  • Revision ID: tarmac-20130325225508-bvhjuwnzzeuh1nof
add FAQ section with objectName memory consumtion Q&A.

Approved by Thomi Richards, Albert Astals Cid, PS Jenkins bot, Martin Mrazik.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Frequently asked questions
 
2
++++++++++++++++++++++++++
 
3
 
 
4
Q. If we add objectNames to QML items all over. What is the impact on memory?
 
5
=============================================================================
 
6
 
 
7
The objectName is a QString property of QObject which defaults to QString().
 
8
QString is UTF-16 representation and because it uses some general purpose
 
9
optimisations it usually allocates twice the space it needs to be able to grow
 
10
fast. It also uses implicit sharing with copy-on-write and other similar
 
11
tricks to increase performance again. These properties makes the used memory
 
12
not straightforward to predict. For example, copying an object with an
 
13
objectName, shares the memory between both as long as they are not changed.
 
14
 
 
15
When measuring memory consumption, things like memory alignment come into play.
 
16
Due to the fact that QML is interpreted by a JavaScript engine, we are working
 
17
in levels where lots of abstraction layers are in between the code and the
 
18
hardware and we have no chance to exactly measure consumption of a single
 
19
objectName property. Therefore the taken approach is to measure lots of items
 
20
and calculate the average consumption.
 
21
 
 
22
Measurement of memory consumption of 10000 Items
 
23
 
 
24
* without objectName: 65292 kB
 
25
* with unique objectName ("item_0" .. "item_9999"): 66628 kB
 
26
* with same objectName: 66480 kB
 
27
 
 
28
=> With 10000 different objectNames 1336 kB of memory are consumed which is
 
29
around 127 Bytes per Item.
 
30
 
 
31
Indeed, this is more than only the string. Some of the memory is certainly lost
 
32
due to memory alignment where certain areas are just not perfectly filled in
 
33
but left empty. However, certainly not all of the overhead can be blamed on
 
34
that. Additional memory is used by the QObject meta object information that is
 
35
needed to do signal/slot connections. Also, QML does some optimisations: It
 
36
does not connect signals/slots when not needed. So the fact that the object
 
37
name is set could trigger some more connections.
 
38
 
 
39
Even if more than the actual string size is used and QString uses a large 
 
40
representation, this is very little compared to the rest. A qmlscene with just 
 
41
the item is 27MB. One full screen image in the Nexus 10 tablet can easily 
 
42
consume around 30MB of memory. So objectNames are definitely not the first
 
43
places where to search for optimisations.
 
44
 
 
45
Writing the test code snippets, one interesting thing came up frequently: Just 
 
46
modifying the code around to set the objectName often influences the results 
 
47
more than the actual string. For example, having a javascript function that
 
48
assigns the objectName definitely uses much more memory than the objectName
 
49
itself. Unless it makes sense from a performance point of view (frequently
 
50
changing bindings can be slow), objectNames should be added by directly
 
51
binding the value to the property instead using helper code to assign it.
 
52
 
 
53
Conclusion: If an objectName is needed for testing, this is definitely worth
 
54
it. objectName's should obviously not be added when not needed. When adding
 
55
them, the general QML guidelines for performance should be followed:
 
56
http://qt-project.org/doc/qt-5.0/qtquick/qtquick-performance.html