Results 1 to 8 of 8

Thread: QT inconsistent performance !!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question QT inconsistent performance !!!

    Hello,

    I have an email model displayed in a QTreeView with check boxes (~ 1500 emails).

    I have a function that loads a string of email addresses(seperated by commas) saved in a SQLite database and translates them to a QStringList (~ 900 emails).
    Then I iterate over the email model, if an email address is found in the QStringList the checkbox is checked, otherwise its unchecked.

    Qt Code:
    1. QTime time1 = QTime::currentTime();
    2. QStringList emails = campaignModel->data(campaignModel->index(index,5)).toString().split(",",QString::SkipEmptyParts);
    3. QStandardItem *parentItem;
    4.  
    5. for (int i=0;i<emailModel->rowCount();i++) {
    6. qApp->processEvents();
    7. parentItem = emailModel->item(i,0);
    8. if (emails.contains(parentItem->data(0).toString()))
    9. parentItem->setCheckState(Qt::Checked);
    10. else
    11. parentItem->setCheckState(Qt::Unchecked);
    12. }
    13. QTime time2 = QTime::currentTime();
    14. qDebug() << "Benchmark0: " << time1.msecsTo(time2);
    To copy to clipboard, switch view to plain text mode 

    My question is how come the first time i run the compiled exe file it takes about 30 msecs to execute the function.
    But whenever i call the function after that, it takes about 300 msec ?!

    any ideas or feedback would be appreciated ?
    Thanks.

  2. #2
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QT inconsistent performance !!!

    Maybe take out qApp->processEvents() and check again. The execution time of that line will depend on the number of events in the QApplication's event queue.

  3. #3
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT inconsistent performance !!!

    Thanks for the reply JPNaude,

    I removed that command and i got a slight improvement on the subsequent calls,
    The first run is still about 30 msec and around 250 msec for all subsequent runs.
    I still can't explain that huge difference.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT inconsistent performance !!!

    in order to narrow down where the bottleneck is, try putting 'time1' just before the 'for' loop.
    See if the change is in the 'for' or in the model query.
    My guess its in the model query, and if so, you have to check your code there.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT inconsistent performance !!!

    Hello high_flyer,

    Thanks for the suggestion, I ran a couple of tests and it turns out the delay is comming for the following commands:
    Qt Code:
    1. parentItem->setCheckState(Qt::Checked);
    To copy to clipboard, switch view to plain text mode 
    and:
    Qt Code:
    1. parentItem->setCheckState(Qt::Unchecked);
    To copy to clipboard, switch view to plain text mode 

    When i changed the code to the one shown below the for loop takes about 30 msec on every run:
    Qt Code:
    1. QTime time1 = QTime::currentTime();
    2. for (int i=0;i<emailModel->rowCount();i++) {
    3. //qApp->processEvents();
    4. parentItem = emailModel->item(i,0);
    5. if (emails.contains(parentItem->data(0).toString())){}
    6. //parentItem->setCheckState(Qt::Checked);
    7. else{}
    8. //parentItem->setCheckState(Qt::Unchecked);
    9. }
    10. QTime time2 = QTime::currentTime();
    11. qDebug() << "Benchmark4: " << time1.msecsTo(time2);
    To copy to clipboard, switch view to plain text mode 

    Is there a workaround to this ? or maybe a more efficient way to achieve what i'm trying to do ?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT inconsistent performance !!!

    Is there a workaround to this ?
    Well its like JPNaude said, each setCheckState() triggers an event, it is probably many in your case.
    One way perhaps is to put this part of a code in to worker thread, and send signals to the items from it.
    This will ensure your loop runs in constant time, but it might still take longer for the GUI to update the all checks.
    But 300 ms is not such a bad time, its a 0.3 of sec, for ~1500 gui items I think its ok... I mean, this is email app not real time app...

    Oh, another thing -
    you can change the design as follows:
    you add a bool to your items to hold their checked state, but actually set the check box only on visible items (in a separate loop maybe), which will usually be far less than 1500.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT inconsistent performance !!!

    You might also try calling blockSignals(true/false) before and after your setCheckState() calls. Although this could be bad if anything else needs to hear about the change.

  8. #8
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT inconsistent performance !!!

    Thanks to all for the feedback.

    I used SixDegrees idea to blockSignals, and i manually called the QTreeView update function on the items and that did the trick.

    Qt Code:
    1. QTime time1 = QTime::currentTime();
    2. emailModel->blockSignals(true);
    3. ui->emailView->blockSignals(true);
    4. for (int i=0;i<emailModel->rowCount();i++) {
    5. parentItem = emailModel->item(i,0);
    6. if (emails.contains(parentItem->data(0).toString()))
    7. parentItem->setCheckState(Qt::Checked);
    8. else
    9. parentItem->setCheckState(Qt::Unchecked);
    10. ui->emailView->update(parentItem->index());
    11. }
    12. ui->emailView->blockSignals(false);
    13. emailModel->blockSignals(false);
    14. QTime time2 = QTime::currentTime();
    15. qDebug() << "Benchmark4: " << time1.msecsTo(time2);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt GUI Performance Help!
    By SeppBauer in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 27th July 2013, 05:18
  2. Webpage snapshot program is inconsistent
    By adamkauk in forum Newbie
    Replies: 0
    Last Post: 10th November 2009, 20:04
  3. Inconsistent behaviour of QVBoxLayout
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 18:36
  4. Qt performance
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2008, 22:05
  5. Compilation Error: "inconsistent operand constraints in an `asm'"
    By jayanth in forum Installation and Deployment
    Replies: 3
    Last Post: 3rd April 2008, 16:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.