PDA

View Full Version : Performance problems with subclassed QAbstractItemModel



fxrb
20th June 2010, 16:46
I have created my own data model derived from QAbstractItemModel. The model is used to store communication trace data row by row. A row holds the data of an inbound or outbound packed. The packet's information is split across different columns such as 'Timestampt', 'Source', 'Destination' etc. The row buffer has a configurable size and if it gets full the oldest row (the first in the model) is discarded and the new row gets appended (as last row). To display the data I use QTreeView.

Things are working fine but the performance is poor. When I use more then 10 rows scrolling is very slow and the processor load is somewhere between 35% to 80%!

My data model implements the following methods from QAbstractItemModel:
- columnCount
- rowCount
- index
- parent
- data;
- headerData

My own method 'AppendRow' to add a row of trace information uses 'beginInsertRows' and 'endInsertRows' to do the job.

I am pretty sure that I missed something very important in my implementation of the sublassed QAbstractItemModel but I just can't imagine what and where the performance lost comes from. Using gprof I found that the method 'data' uses up most of the time but I think this is quite logic and correct as it is the method called over and over again from the view to get information about what to display, right?
So, what did I really miss? Can anybody give me a hint?

Many thanks Felix

fxrb
7th July 2010, 09:38
I have used 'ModelTest' from http://labs.trolltech.com/page/Projects/Itemview/Modeltest, hoping it could give me some hint. It is a good tool but it did not help with the performance problem.

I somehow feel that when I append an item at the end of my list everything (all items) get reordered by the view and that this could be the problem. Years ago we wrote a Windows application which is also able to trace communication; this application is still running and it's performance is excellent, no matter how long (how many lines) the trace buffer has. Only problem: it is programmed for Windows so it is not portable.

Is there really nobody who could push me in the right direction? Is there eventually somewhat like 'ModelTest' that could analyze errors which result in bad performance?

fxrb
7th July 2010, 16:00
Some more information:

During debugging I found Qt call my model's data member for each column and each row every time I append a row. It does this no matter how many rows are visible in the view, i.e. if my data model has 500 rows and 30 rows are visible the view requests all data including the data for the 470 rows that are not visible. No wonder everything is getting very slow and the CPU load increases.
What I do net yet know is how to solve this problem since I do not seem to understand how the view decides about which data it should request from the model.

gitarooLegend
24th February 2011, 14:46
Are you using "emit dataChanged(QModelIndex& topLeft, QModelIndex& bottomRight)"?

See:
http://doc.qt.nokia.com/latest/qabstractitemmodel.html#dataChanged

This signal should be emitted whenever your data changes. The arguments tell your view which data members should be updated. I believe your view will only call "data" on the cells between the ones you specify and only when you emit this signal. Maybe you are emitting the signal too often, or including too much of your list. Try narrowing your topLeft and bottomRight to only surround the ones that you changed.

I'm actually having some performance issues with this as well. Does anyone know of a general way to speed this up, or something faster than the QAbstractTableModel/QTableView?