How to optimize Containers: Difference between revisions
No edit summary |
m (repaired broken link) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:HowTo]] | |||
{{WarningBox|text=This article contains missing references. Feel free to add them and remove this warning afterwards}} | |||
= | 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 white paper <span style="color:rgb(200,100,100);font-size:.8em"><nowiki>[Reference missing]</nowiki></span>. | ||
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 | |||
== Container selection == | == Container selection == | ||
Line 11: | Line 9: | ||
Let's continue with three representative container classes and how container type impacts performance. | 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. | * {{DocLink|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. | * {{DocLink|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. | * {{DocLink|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 == | == Additional reading == | ||
* | * [http://doc.qt.io/qt-5/containers.html Container class documentation from 5.x release] | ||
* [http://doc.qt.io/archives/qq/qq19-containers.html Inside the Qt 4 Containers] - Qt Quarterly #19 article about internal implementation | |||
* |
Latest revision as of 18:50, 29 May 2017
This article contains missing references. Feel free to add them and remove this warning afterwards |
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 white paper [Reference missing].
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
- Container class documentation from 5.x release
- Inside the Qt 4 Containers - Qt Quarterly #19 article about internal implementation