How to optimize Containers: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Performance Tip: Optimizing Containers=
[[Category:Learning]]<br />[[Category:HowTo]]<br />[[Category:Developing with Qt]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]


The developers of the Qt framework spend a lot of time packing performance into their code. The Qt 4 release back in 2008 focused on performance, and they released some documentation at the time to help developers leverage the upgrade. Some of the discussions at the time are still worth reviewing, including a discussion about container optimization summarized here. A detailed discussion of performance issues is available in the [http://qt.nokia.com/products/library/forms/whitepapers/reg-whitepaper-performance Maximizing Performance with Qt] ''[qt.nokia.com]'' white paper.
= Performance Tip: Optimizing Containers =


==Container selection==
The developers of the Qt framework spend a lot of time packing performance into their code. The Qt 4 release back in 2008 focused on performance, and they released some documentation at the time to help developers leverage the upgrade. Some of the discussions at the time are still worth reviewing, including a discussion about container optimization summarized here. A detailed discussion of performance issues is available in the &quot;Maximizing Performance with Qt&amp;quot;:http://qt.nokia.com/products/library/forms/whitepapers/reg-whitepaper-performance white paper.


Let’s start with the obvious: containers are fundamental building blocks of software applications. How quickly data can be moved into and out of containers is a critical factor in the application’s overall performance. Qt 4.5 included optimizations which sped up the performance of most containers, which means better performance for all Qt applications. The optimization of containers has continued through the 4.6 and upcoming 4.7 releases.
== Container selection ==


Let’s continue with three representative container classes and how container type impacts performance.
Let's start with the obvious: containers are fundamental building blocks of software applications. How quickly data can be moved into and out of containers is a critical factor in the application's overall performance. Qt 4.5 included optimizations which sped up the performance of most containers, which means better performance for all Qt applications. The optimization of containers has continued through the 4.6 and upcoming 4.7 releases.
 
Let's continue with three representative container classes and how container type impacts performance.


* QVector is optimized for accessing data at the expense of slowing the process of data insertion and deletion. The QVector class stores an array of values of a given type at adjacent positions in memory. Inserting at the front or in the middle of a vector can be quite slow, because it can lead to large numbers of items having to be moved by one position in memory.
* QVector is optimized for accessing data at the expense of slowing the process of data insertion and deletion. The QVector class stores an array of values of a given type at adjacent positions in memory. Inserting at the front or in the middle of a vector can be quite slow, because it can lead to large numbers of items having to be moved by one position in memory.
Line 13: Line 15:
* QLinkedList is optimized for the other extreme: this classic linked list pattern makes insertion and deletion of items lightning quick, but accessing an item requires iteration over the list.
* QLinkedList is optimized for the other extreme: this classic linked list pattern makes insertion and deletion of items lightning quick, but accessing an item requires iteration over the list.


* QList is by far the most commonly used container class. More than any other container class, QList is highly optimized to expand to as little code as possible in the executable. It stores a list of values of a given type that can be accessed by index. Internally, the QList is implemented using an array, ensuring that index-based access is very fast.
* QList is by far the most commonly used container class. More than any other container class, QList is highly optimized to expand to as little code as possible in the executable. It stores a list of values of a given type that can be accessed by index. Internally, the QList is implemented using an array, ensuring that index-based access is very fast.  
 
==Additional reading==
 
* [http://qt.nokia.com/products/library/forms/whitepapers/reg-whitepaper-performance Maximizing Performance with Qt] ''[qt.nokia.com]'' white paper.
* [http://doc.trolltech.com/4.6/containers.html Container class documentation from 4.6 release] ''[doc.trolltech.com]''
* [http://doc.qt.nokia.com/qq/qq19-containers.html Inside the Qt 4 Containers] ''[doc.qt.nokia.com]'' – Qt Quarterly #19 article about internal implementation


===Categories:===
== Additional reading ==


* [[:Category:Developing with Qt|Developing_with_Qt]]
* &quot;Maximizing Performance with Qt&amp;quot;:http://qt.nokia.com/products/library/forms/whitepapers/reg-whitepaper-performance white paper.
* [[:Category:HowTo|HowTo]]
* &quot;Container class documentation from 4.6 release&amp;quot;:http://doc.trolltech.com/4.6/containers.html
* [[:Category:Learning|Learning]]
* &quot;Inside the Qt 4 Containers&amp;quot;:http://doc.qt.nokia.com/qq/qq19-containers.html - Qt Quarterly #19 article about internal implementation

Revision as of 10:28, 24 February 2015




[toc align_right="yes&quot; depth="2&quot;]

Performance Tip: Optimizing Containers

The developers of the Qt framework spend a lot of time packing performance into their code. The Qt 4 release back in 2008 focused on performance, and they released some documentation at the time to help developers leverage the upgrade. Some of the discussions at the time are still worth reviewing, including a discussion about container optimization summarized here. A detailed discussion of performance issues is available in the "Maximizing Performance with Qt&quot;:http://qt.nokia.com/products/library/forms/whitepapers/reg-whitepaper-performance white paper.

Container selection

Let's start with the obvious: containers are fundamental building blocks of software applications. How quickly data can be moved into and out of containers is a critical factor in the application's overall performance. Qt 4.5 included optimizations which sped up the performance of most containers, which means better performance for all Qt applications. The optimization of containers has continued through the 4.6 and upcoming 4.7 releases.

Let's continue with three representative container classes and how container type impacts performance.

  • QVector is optimized for accessing data at the expense of slowing the process of data insertion and deletion. The QVector class stores an array of values of a given type at adjacent positions in memory. Inserting at the front or in the middle of a vector can be quite slow, because it can lead to large numbers of items having to be moved by one position in memory.
  • QLinkedList is optimized for the other extreme: this classic linked list pattern makes insertion and deletion of items lightning quick, but accessing an item requires iteration over the list.
  • QList is by far the most commonly used container class. More than any other container class, QList is highly optimized to expand to as little code as possible in the executable. It stores a list of values of a given type that can be accessed by index. Internally, the QList is implemented using an array, ensuring that index-based access is very fast.

Additional reading