PDA

View Full Version : QTreeView + QSortFilterProxyModel + Subclassed QAbstractItemModel : Performance issue



adith387
8th December 2010, 19:09
Hi,

I have a QTreeView that displays realtime information for about 400 items. At a time, only about 10 rows are visible in the treeview. The CPU utilization is very very high (and performance is very bad).
Currently, in my model, any time one of the item's data is changed in the underlying datastore, I emit a dataChanged signal.
To optimise this a bit, I maintained a integer topmostItem and integer bottommostItem, and in a 20 msec window, all the changes in the datastore are aggregated and I emit a dataChanged(createIndex(...topmostRow), ...bottommostRow). Even this has very bad performance.

What must I do to improve performance?

Thanks in advance.

franz
8th December 2010, 19:59
Did you try taking out the proxy model? It is reportedly slow. If that doesn't do it, you probably need a slightly different approach. I'm not sure how fast your data comes in, but if you gather data in a 20 ms window (50Hz) you are probably displaying data faster than you can read in the first place. Is the high update rate required in your case?

adith387
8th December 2010, 20:37
Hi,

I did remove the proxy model to see if CPU utilization goes down : it doesnt.

The data comes in very fast (once every couple of milliseconds, say), and I figured, I need not emit a dataChanged everytime a new data event happens. I also figured 50Hz was a reasonable refresh rate (if I concentrate on only one item, I should be able to see it change in pseudo-real-time).

I also ran gprof to see where Qt spends the most time,


Flat profile:

Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
21.14 0.74 0.74 92921396 0.00 0.00 QBasicAtomicInt::ref()
20.57 1.46 0.72 95210967 0.00 0.00 QBasicAtomicInt::deref()
5.71 1.66 0.20 79832888 0.00 0.00 QString::~QString()
5.14 1.84 0.18 77860385 0.00 0.00 QString::QString(QString const&)
3.86 1.98 0.14 49350258 0.00 0.00 QList<QString>::detach()
2.43 2.06 0.09 56066724 0.00 0.00 QBasicAtomicInt::operator!=(int) const

Not quite helpful. I commented out the emitting of dataChanged, and the CPU utilization drops to near-0 ... which makes me wonder if somehow I can figure out if the item whose data is being changed is visible in the view's viewport (the majority of the items are hidden ... and furthermore, if item A is at the top and item B at the bottom, and these 2 get updated in a 20 ms window, I am currently emitting dataChanged for the entire rectangle defined by these two end-points ... )

Is there any way to improve performance? (Sorting is very desirable in the app ... not necessarily real-time sorting, but sorting on the non-realtime columns).