Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, October 2007
Qt 4.3.2, slow QTreeWidgetItem::setHidden(bool) !?

Pages: Prev | 1 | 2 | Next

Message 16 in thread

On Thursday 18 October 2007 17:27:35 R. Reucher wrote:
> On Wed, October 17, 2007 12:42, Benjamin Meyer wrote:
> > Attached is a patch for qtreeview and qtreewidget.  With this patch
> > applied a test application have written is significantly (10 - 1000X)
> > faster.  When inserting a row it removes the forced layout (when
> > possible) and fixes several bugs that were hidden by the forced layout
> > and surfaced once it was removed.
>
> Benjamin,
>
> I tried your patch, and yes, with my application (QMC2), it IS faster than
> before (2-3 times), but it's still dramatically slower than with Qt 4.2.0 -
> 4.3.1.
>
> It now takes about 16 seconds, compared to 30-40 seconds without your
> patch.
>
> Hmmm... do you see any chance to further speed it up?
>
> Regards, René

Yah, can you make a small example that highlights the behavior that you would 
like to have speed up?

-Benjamin Meyer

--
 [ signature omitted ] 

Message 17 in thread

On Fri, October 19, 2007 11:43, Benjamin Meyer wrote:
> Yah, can you make a small example that highlights the behavior that you
> would like to have speed up?
Well, I have no short example at hand... but let me illustrate the relevant
code-snippet from my application:

...
  bool show0 = mySettings->value("Show0").toBool();
  bool show1 = mySettings->value("Show1").toBool();
  bool show2 = mySettings->value("Show2").toBool();
  bool show3 = mySettings->value("Show3").toBool();
  bool show4 = mySettings->value("Show4").toBool();
  QMapIterator<QString, QTreeWidgetItem *> it(myItemMap);
  while ( it.hasNext() ) {
    it.next();
    QTreeWidgetItem *item = it.value();
    switch ( item->whatsThis(0).at(0).toAscii() ) {
      case '0':
        item->setHidden(!show0);
        break;

      case '1':
        item->setHidden(!show1);
        break;

      case '2':
        item->setHidden(!show2);
        break;

      case '3':
        item->setHidden(!show3);
        break;

      case '4':
      default:
        item->setHidden(!show4);
        break;
    }
  }
...

That's it, basically...

Does that help in any way?

Regards, René
-- 
 [ signature omitted ] 

Message 18 in thread

On Friday 19 October 2007 11:57:42 R. Reucher wrote:
> On Fri, October 19, 2007 11:43, Benjamin Meyer wrote:
> > Yah, can you make a small example that highlights the behavior that you
> > would like to have speed up?
>
> Well, I have no short example at hand... but let me illustrate the relevant
> code-snippet from my application:

/me tosses out magical fairy dust to turn code into an example

How is this?  Profiling it looks like there might some improvements that can 
be made in QTreeView.

-Benjamin Meyer

#include <QtGui/QtGui>

void addChildren(QTreeWidgetItem *parent, int depth = 0)
{
    QList<QTreeWidgetItem *> children;
    for (int i = 0; i < 6; ++i) {
        QTreeWidgetItem *item =
            new QTreeWidgetItem(QStringList(QString("item: %1").arg(i)));
        children.append(item);
        if (depth < 4)
            addChildren(item, depth + 1);
    }
    parent->addChildren(children);
}

void swap(QTreeWidgetItem *parent)
{
    if (parent->childCount() > 0 && (qrand() % 4 == 2)) {
        int row = qrand() % parent->childCount();
        swap(parent->child(row));
        return;
    }
    parent->setHidden(!parent->isHidden());
}

int main(int argc,char **argv) {
    QApplication application(argc, argv);
    QTreeWidget treeWidget;
    treeWidget.setColumnCount(1);
    addChildren(treeWidget.invisibleRootItem());
    treeWidget.show();

    qsrand(time(0));
    for (int i = 0; i < 1000; ++i)
        swap(treeWidget.invisibleRootItem());
    return 0;
}

--
 [ signature omitted ] 

Message 19 in thread

On Friday 19 October 2007 15:03:25 Benjamin Meyer wrote:
> On Friday 19 October 2007 11:57:42 R. Reucher wrote:
> > On Fri, October 19, 2007 11:43, Benjamin Meyer wrote:
> > > Yah, can you make a small example that highlights the behavior that you
> > > would like to have speed up?
> >
> > Well, I have no short example at hand... but let me illustrate the
> > relevant code-snippet from my application:

[snip]

Applying the patch below should give your application a good speed 
improvement.  There are bigger changes that could be made, but this was the 
smallest change with the best result that I am confident will no cause any 
harmful sideeffects.

-Benjamin Meyer

==== qtreeview.cpp#51 - qtreeview.cpp ====
@@ -517,7 +517,6 @@
     if (!index.isValid())
         return;

-    d->executePostedLayout();
     if (hide) {
         QPersistentModelIndex persistent(index);
         if (!d->hiddenIndexes.contains(persistent))
@@ -546,6 +545,7 @@
                     i += count;
                 }
             }
+            d->executePostedLayout();
             updateGeometries();
             d->viewport->update();
         } else {

--
 [ signature omitted ] 

Message 20 in thread

On Fri, October 19, 2007 16:02, Benjamin Meyer wrote:
> On Friday 19 October 2007 15:03:25 Benjamin Meyer wrote:
>> On Friday 19 October 2007 11:57:42 R. Reucher wrote:
>>> On Fri, October 19, 2007 11:43, Benjamin Meyer wrote:
>>>
>>>> Yah, can you make a small example that highlights the behavior that
>>>> you would like to have speed up?
>>>
>>> Well, I have no short example at hand... but let me illustrate the
>>> relevant code-snippet from my application:
>
> [snip]
No, I think I have to apologise for not providing a good example... I just
didn't have the time to create one, but this is no excuse.

> Applying the patch below should give your application a good speed
> improvement.  There are bigger changes that could be made, but this was the
> smallest change with the best result that I am confident will no cause any
> harmful sideeffects.
>
> -Benjamin Meyer
>
>
> ==== qtreeview.cpp#51 - qtreeview.cpp ====
> @@ -517,7 +517,6 @@
> if (!index.isValid()) return;
>
> -    d->executePostedLayout();
> if (hide) { QPersistentModelIndex persistent(index);
> if (!d->hiddenIndexes.contains(persistent)) @@ -546,6 +545,7 @@
> i += count; }
> }
> +            d->executePostedLayout();
> updateGeometries(); d->viewport->update(); } else {
Yeah, this is it!!!

The results are as good as expected, that is the speed is back to what I was
used to :)!

Thanks a lot!

Can we expect this change to be part of 4.3.3?

Regards, René
-- 
 [ signature omitted ] 

Message 21 in thread

On Friday 19 October 2007 16:23:05 R. Reucher wrote:
> On Fri, October 19, 2007 16:02, Benjamin Meyer wrote:
> > On Friday 19 October 2007 15:03:25 Benjamin Meyer wrote:
> >> On Friday 19 October 2007 11:57:42 R. Reucher wrote:
> >>> On Fri, October 19, 2007 11:43, Benjamin Meyer wrote:
> >>>> Yah, can you make a small example that highlights the behavior that
> >>>> you would like to have speed up?
> >>>
> >>> Well, I have no short example at hand... but let me illustrate the
> >>> relevant code-snippet from my application:
> >
> > [snip]
>
> No, I think I have to apologise for not providing a good example... I just
> didn't have the time to create one, but this is no excuse.
>
> > Applying the patch below should give your application a good speed
> > improvement.  There are bigger changes that could be made, but this was
> > the smallest change with the best result that I am confident will no
> > cause any harmful sideeffects.
> >
> > -Benjamin Meyer
> >
> >
> > ==== qtreeview.cpp#51 - qtreeview.cpp ====
> > @@ -517,7 +517,6 @@
> > if (!index.isValid()) return;
> >
> > -    d->executePostedLayout();
> > if (hide) { QPersistentModelIndex persistent(index);
> > if (!d->hiddenIndexes.contains(persistent)) @@ -546,6 +545,7 @@
> > i += count; }
> > }
> > +            d->executePostedLayout();
> > updateGeometries(); d->viewport->update(); } else {
>
> Yeah, this is it!!!
>
> The results are as good as expected, that is the speed is back to what I
> was used to :)!
>
> Thanks a lot!
>
> Can we expect this change to be part of 4.3.3?
>
> Regards, René

Yes, it was put in 4.3 and will be in tonight's snapshot.

-Benjamin Meyer

--
 [ signature omitted ]