Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, April 2007
QTreeWidget performance


Message 1 in thread

Hi,

I use a QTreeWidget where I add individual items whether they become ready to 
show. The performance degrades a *lot* when the number of items is above 
~1000, to a point that is nearly unusable.

I'm certain that the bottleneck is in QTreeWidget because I profiled it with 
cachegrind. I also ran only the engine, and it was really fast.

Can I expect this widget to be optimized in order to deal with a couple of 
thousands of items or should I find another solution?

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 2 in thread

On Monday 23 April 2007 23:11, Paulo Moura Guedes wrote:
> Hi,
>
> I use a QTreeWidget where I add individual items whether they become ready
> to show. The performance degrades a *lot* when the number of items is above
> ~1000, to a point that is nearly unusable.
>
> I'm certain that the bottleneck is in QTreeWidget because I profiled it
> with cachegrind. I also ran only the engine, and it was really fast.
>
> Can I expect this widget to be optimized in order to deal with a couple of
> thousands of items or should I find another solution?
>
> Paulo

Was this tested against the snapshot or a particular release?  There have been 
a handfull of performance related improvements made in different releases.  
Do you have a example showing the code path that you are using?

With QTreeWidget one tip that will allways improve performance is to use  
addTopLevelItems() once rather then addTopLevelItem() a bunch of times.  (and 
addChildren() vs addChild() in QTreeWidgetItem)

-Benjamin Meyer

Attachment:

Attachment: pgppRFsBiSzhc.pgp
Description: PGP signature


Message 3 in thread

On Tuesday 24 April 2007 08:19, Benjamin Meyer wrote:
> On Monday 23 April 2007 23:11, Paulo Moura Guedes wrote:
> > Hi,
> >
> > I use a QTreeWidget where I add individual items whether they become
> > ready to show. The performance degrades a *lot* when the number of items
> > is above ~1000, to a point that is nearly unusable.
> >
> > I'm certain that the bottleneck is in QTreeWidget because I profiled it
> > with cachegrind. I also ran only the engine, and it was really fast.
> >
> > Can I expect this widget to be optimized in order to deal with a couple
> > of thousands of items or should I find another solution?
> >
> > Paulo
>
> Was this tested against the snapshot or a particular release?  

Against 4.3 beta, i.e., qt-copy before this monday update.

> There have
> been a handfull of performance related improvements made in different
> releases. Do you have a example showing the code path that you are using?

Yes, I'm doing just individual inserts:

new QTreeWidgetItem (QTreeWidgetItem* parent, QTreeWidgetItem* preceding);

> With QTreeWidget one tip that will allways improve performance is to use
> addTopLevelItems() once rather then addTopLevelItem() a bunch of times. 
> (and addChildren() vs addChild() in QTreeWidgetItem)

Yes, of course, but I don't think the user would like to wait a couple of 
minutes before seing something appear. 

Thanks
Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 4 in thread

On Tuesday 24 April 2007 11:46, Paulo Moura Guedes wrote:
> On Tuesday 24 April 2007 08:19, Benjamin Meyer wrote:
> > On Monday 23 April 2007 23:11, Paulo Moura Guedes wrote:
> > > Hi,
> > >
> > > I use a QTreeWidget where I add individual items whether they become
> > > ready to show. The performance degrades a *lot* when the number of
> > > items is above ~1000, to a point that is nearly unusable.
> > >
> > > I'm certain that the bottleneck is in QTreeWidget because I profiled it
> > > with cachegrind. I also ran only the engine, and it was really fast.
> > >
> > > Can I expect this widget to be optimized in order to deal with a couple
> > > of thousands of items or should I find another solution?
> > >
> > > Paulo
> >
> > Was this tested against the snapshot or a particular release?
>
> Against 4.3 beta, i.e., qt-copy before this monday update.
>
> > There have
> > been a handfull of performance related improvements made in different
> > releases. Do you have a example showing the code path that you are using?
>
> Yes, I'm doing just individual inserts:
>
> new QTreeWidgetItem (QTreeWidgetItem* parent, QTreeWidgetItem* preceding);
[snip]
> Thanks
> Paulo
>
> To unsubscribe - send "unsubscribe" in the subject to
> qt4-preview-feedback-request@xxxxxxxxxxxxx

I tried to make an example and noticed that the 
QTreeWidget::QTreeWidget(parent, preceding) constructor is 20X slower then 
the QTreeWidget(parent) constructor and have made task 159871 to see if there 
is anything that can be done about that.  But with 1000 items this still runs 
in less then a second on my box.  Can you modify the following code to 
produce the slowdown that you are seeing?

-Benjamin Meyer 

#include <QtGui>
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QTreeWidget w;
    w.setColumnCount(1);
    QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
    QTreeWidgetItem *child = new QTreeWidgetItem(parent);
    for (int i = 0; i < 1000; ++i) {
        child = new QTreeWidgetItem(parent, child);
    }
}

Attachment:

Attachment: pgp8gKFxIsj61.pgp
Description: PGP signature


Message 5 in thread

On Tuesday 24 April 2007 12:11, Benjamin Meyer wrote:
> I tried to make an example and noticed that the
> QTreeWidget::QTreeWidget(parent, preceding) constructor is 20X slower then
> the QTreeWidget(parent) constructor and have made task 159871 to see if
> there is anything that can be done about that.  

I think I can use the QTreeWidget(parent) constructor, thanks for the tip!

> But with 1000 items this
> still runs in less then a second on my box.  Can you modify the following
> code to produce the slowdown that you are seeing?

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QTreeWidget w;
    w.setColumnCount(3);
    QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
    QTreeWidgetItem *child = new QTreeWidgetItem(parent);
    for (int i = 0; i < 1000; ++i) {
        child = new QTreeWidgetItem(parent, child);
        child->setText(0, "boo1");
        child->setText(1, "boo2");
        child->setText(2, "boo3");
        scrollToItem(child, QAbstractItemView::PositionAtCenter);
        qApp->processEvents();
    }
}

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 6 in thread

On Tuesday 24 April 2007 13:44, Paulo Moura Guedes wrote:
> > But with 1000 items this
> > still runs in less then a second on my box.  Can you modify the following
> > code to produce the slowdown that you are seeing?
>
> int main(int argc, char **argv)
> {
>     QApplication app(argc, argv);
>     QTreeWidget w;
>     w.setColumnCount(3);
>     QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
>     QTreeWidgetItem *child = new QTreeWidgetItem(parent);
>     for (int i = 0; i < 1000; ++i) {
>         child = new QTreeWidgetItem(parent, child);
>         child->setText(0, "boo1");
>         child->setText(1, "boo2");
>         child->setText(2, "boo3");
>         scrollToItem(child, QAbstractItemView::PositionAtCenter);
>         qApp->processEvents();
>     }
> }

I raised the iterations to 2000 and inserted a print out in each iteration and 
I can see that it really slows down when the number of items grow.
The problem seems to be in the graphics, i.e., in displaying the content. The 
inserting in QTreeWidget itself seems very fast.

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 7 in thread

On Tuesday 24 April 2007 14:30, BH wrote:
> > I raised the iterations to 2000 and inserted a print out in each
> > iteration and I can see that it really slows down when the number of
> > items grow. The problem seems to be in the graphics, i.e., in displaying
> > the content. The inserting in QTreeWidget itself seems very fast.
>
> See http://doc.trolltech.com/4.2/qwidget.html#updatesEnabled-prop
>
> Aka you'll want to do:
> setUpdatesEnabled(false);
> Insert_2000_items_in_tree();
> setUpdatesEnabled(true);
>
> This will conserve 1999 unnecessary repaints after each insert ;)

Please see the previous posts. I insert items when they become ready and want 
the user to have some feedback, aka don't have to wait 10 minutes before 
something appears on the screen.

As Peter suggested, I will use a timer to do the scrollToItem stuff. Unless 
I'm missing something, it seems the only option I have.

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 8 in thread

On Tuesday 24 April 2007 14:44, Paulo Moura Guedes wrote:
> On Tuesday 24 April 2007 12:11, Benjamin Meyer wrote:
> > I tried to make an example and noticed that the
> > QTreeWidget::QTreeWidget(parent, preceding) constructor is 20X slower
> > then the QTreeWidget(parent) constructor and have made task 159871 to see
> > if there is anything that can be done about that.
>
> I think I can use the QTreeWidget(parent) constructor, thanks for the tip!
>
> > But with 1000 items this
> > still runs in less then a second on my box.  Can you modify the following
> > code to produce the slowdown that you are seeing?
>
> int main(int argc, char **argv)
> {
>     QApplication app(argc, argv);
>     QTreeWidget w;
>     w.setColumnCount(3);
>     QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
>     QTreeWidgetItem *child = new QTreeWidgetItem(parent);
>     for (int i = 0; i < 1000; ++i) {
>         child = new QTreeWidgetItem(parent, child);
>         child->setText(0, "boo1");
>         child->setText(1, "boo2");
>         child->setText(2, "boo3");
>         scrollToItem(child, QAbstractItemView::PositionAtCenter);
>         qApp->processEvents();
>     }
> }

I have created a suggestion (#159911) to improve the speed of scrollToItem as 
that is the cause of your slowdown and it is slower then it was in 4.2, but 
you probably still want to delay scrolling to the child until after you have 
inserted all of the children.  Making this change will dramatically speed it 
up.

-Benjamin Meyer

Attachment:

Attachment: pgpJqbhq5BwZT.pgp
Description: PGP signature


Message 9 in thread

Another suggestion: after inserting an item, start a timer, so that you only call scrollToItem every few seconds. This way you'll still have most of the functionality without the overhead on every insertion.

Cheers,
Peter

> -----Ursprüngliche Nachricht-----
> Von: Benjamin Meyer [mailto:benjamin.meyer@xxxxxxxxxxxxx]
> Gesendet: Dienstag, 24. April 2007 15:26
> An: qt4-preview-feedback@xxxxxxxxxxxxx
> Betreff: Re: QTreeWidget performance
> 
> On Tuesday 24 April 2007 14:44, Paulo Moura Guedes wrote:
> > On Tuesday 24 April 2007 12:11, Benjamin Meyer wrote:
> > > I tried to make an example and noticed that the
> > > QTreeWidget::QTreeWidget(parent, preceding) constructor is 20X slower
> > > then the QTreeWidget(parent) constructor and have made task 159871 to
> see
> > > if there is anything that can be done about that.
> >
> > I think I can use the QTreeWidget(parent) constructor, thanks for the
> tip!
> >
> > > But with 1000 items this
> > > still runs in less then a second on my box.  Can you modify the
> following
> > > code to produce the slowdown that you are seeing?
> >
> > int main(int argc, char **argv)
> > {
> >     QApplication app(argc, argv);
> >     QTreeWidget w;
> >     w.setColumnCount(3);
> >     QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
> >     QTreeWidgetItem *child = new QTreeWidgetItem(parent);
> >     for (int i = 0; i < 1000; ++i) {
> >         child = new QTreeWidgetItem(parent, child);
> >         child->setText(0, "boo1");
> >         child->setText(1, "boo2");
> >         child->setText(2, "boo3");
> >         scrollToItem(child, QAbstractItemView::PositionAtCenter);
> >         qApp->processEvents();
> >     }
> > }
> 
> I have created a suggestion (#159911) to improve the speed of scrollToItem
> as
> that is the cause of your slowdown and it is slower then it was in 4.2,
> but
> you probably still want to delay scrolling to the child until after you
> have
> inserted all of the children.  Making this change will dramatically speed
> it
> up.
> 
> -Benjamin Meyer

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 10 in thread

On Tuesday 24 April 2007 14:36, Peter Prade wrote:
> Another suggestion: after inserting an item, start a timer, so that you
> only call scrollToItem every few seconds. This way you'll still have most
> of the functionality without the overhead on every insertion.

Yeah, that's very smart, I'll do that.

Thanks
Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 11 in thread

On Tuesday 24 April 2007 14:26, Benjamin Meyer wrote:
> I have created a suggestion (#159911) to improve the speed of scrollToItem
> as that is the cause of your slowdown and it is slower then it was in 4.2,
> but you probably still want to delay scrolling to the child until after you
> have inserted all of the children.  Making this change will dramatically
> speed it up.

OK, thanks a lot for your help!

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 12 in thread

On Tuesday 24 April 2007 14:26, Benjamin Meyer wrote:
> On Tuesday 24 April 2007 14:44, Paulo Moura Guedes wrote:
> > On Tuesday 24 April 2007 12:11, Benjamin Meyer wrote:
> > > I tried to make an example and noticed that the
> > > QTreeWidget::QTreeWidget(parent, preceding) constructor is 20X slower
> > > then the QTreeWidget(parent) constructor and have made task 159871 to
> > > see if there is anything that can be done about that.
> >
> > I think I can use the QTreeWidget(parent) constructor, thanks for the
> > tip!
> >
> > > But with 1000 items this
> > > still runs in less then a second on my box.  Can you modify the
> > > following code to produce the slowdown that you are seeing?
> >
> > int main(int argc, char **argv)
> > {
> >     QApplication app(argc, argv);
> >     QTreeWidget w;
> >     w.setColumnCount(3);
> >     QTreeWidgetItem *parent = new QTreeWidgetItem(&w);
> >     QTreeWidgetItem *child = new QTreeWidgetItem(parent);
> >     for (int i = 0; i < 1000; ++i) {
> >         child = new QTreeWidgetItem(parent, child);
> >         child->setText(0, "boo1");
> >         child->setText(1, "boo2");
> >         child->setText(2, "boo3");
> >         scrollToItem(child, QAbstractItemView::PositionAtCenter);
> >         qApp->processEvents();
> >     }
> > }
>
> I have created a suggestion (#159911) to improve the speed of scrollToItem
> as that is the cause of your slowdown and it is slower then it was in 4.2,
> but you probably still want to delay scrolling to the child until after you
> have inserted all of the children.  Making this change will dramatically
> speed it up.

Fortunately, I already had the scrolling definined has an option. :)
Though, even with the scrolled disabled and uniformRowHeights set to true, 
it's still very slow.
To be sure, I set UpdatesEnabled to false in the QTreeWidget and it's not slow 
anymore.

It seems there is margin to improve here has the QTreeWidget is always showing 
the same thing (if the scrolling is not activated), so it doesn't need to be 
updated.

Paulo

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx