Results 1 to 4 of 4

Thread: Very slow QCoreApplication::removePostedEvents in Qt 4.6

  1. #1
    Join Date
    Oct 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Very slow QCoreApplication::removePostedEvents in Qt 4.6

    Hi,

    I just compiled my code against the official Qt 4.6 (self compiled under Mac OS X 10.5 using gcc 4.2 with cocoa support and for 32bit).

    The same code that ran just fine against the 4.6-tp1 is now experiencing dramatic slow downs. Here is the sample:

    Qt Code:
    1. QObject **qls = new QObject*[COUNT];
    2. for(int i=0; i<COUNT; i++) {
    3. qls[i] = new QObject;
    4. qls[i]->setParent(&a);
    5. }
    6.  
    7. for(int i=0; i<COUNT; i++) {
    8. qls[i]->setParent(0);
    9. delete qls[i];
    10. }
    11.  
    12. delete[] qls;
    To copy to clipboard, switch view to plain text mode 

    runs like this:

    Qt Code:
    1. creation of 10000 objects: 20.294 ms = 2.0293 µs per object
    2. destruction of 10000 objects: 743.141 ms = 74.3141 µs per object
    To copy to clipboard, switch view to plain text mode 

    2µs for creation is just fine. but 74.3µs for the destruction process is crazy. In the 4.6-tp1 the destruction was always faster than creation.

    I took the Mac Process Analyzer and figured out that it stuck 95% of the time in

    Qt Code:
    1. QCoreApplication::removePostedEvents()
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Very slow QCoreApplication::removePostedEvents in Qt 4.6

    Apparently there are some events waiting in the queue for your objects. First I would get rid of the setParent(0) call, it's completely useless. Then I would change your qls variable from QObject** to QObjectList. Then you have to tell us if you do anything with the objects apart from creating and destroying them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Very slow QCoreApplication::removePostedEvents in Qt 4.6

    The thing I am trying to achieve here is to make a statement of the performance of Qt object creation and destruction. If you remember, I asked a couple of weeks ago what would be the disadvantage of making every object (model or view or whatever) a QObject. Since a QObject does something useful, there must be clearly ome overhead involved.

    I must mention that I am a fan of generating code. And, in the meantime, I worked on a prototype which generates a QObject for each and every class in my UML tool. In addition to that, I also generate a QObject for each and every property of that UML class. Reason is, I later want to be able to connect to the attribute of the concrete instance of that class and receive events via signals/slots. However, my first test showed me that the performance was not good. And especially memory consumption was a killer. Creation of an object (QObject) with 20 such property objects (also QObjects) took ~20µs. So I decided to step back and do the old school approach and map the UML properties onto C++ plain old data members.

    Anyhow, once I changed the code generator I switched over to the new Qt 4.6 from the previous Qt-4.6-tp1 and recognized a significant drop in performance of the destruction process. That is why I stripped down my code to a presentable minimum without using too many Qt features at once, like QObjectList or something. Plain QObjects should be constructable and destructable, right? It doesn't matter, where I keep them. I just wanted to make sure that the compiler doesn't optimize them out.

    I'm still not through to this. But I have recognized so far that as soon as I do not wire the objects together via parent-child all is fine. If I connect them, performance drop to inacceptible level.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. const int COUNT = 30000;
    4. QCoreApplication a(argc, argv);
    5.  
    6. Timer clock;
    7. clock.start();
    8.  
    9. QObject *parent = new QObject;
    10. QObject **qls = new QObject*[COUNT];
    11. for(int i=0; i<COUNT; i++) {
    12. qls[i] = new QObject(parent);
    13. }
    14. qDebug() << "creation of" << COUNT << "objects: " << clock.getElapsedTimeInMilliSec() << "ms = "
    15. << clock.getElapsedTimeInMicroSec() / COUNT << "us per object";
    16.  
    17.  
    18. clock.start();
    19. for(int i=0; i<COUNT; i++) {
    20. qls[i]->setParent(0);
    21. delete qls[i];
    22. }
    23. delete[] qls;
    24. delete parent;
    25. qDebug() << "destruction of" << COUNT << "objects: " << clock.getElapsedTimeInMilliSec() << "ms = "
    26. << clock.getElapsedTimeInMicroSec() / COUNT << "us per object";
    27.  
    28. return 0;
    29. }
    To copy to clipboard, switch view to plain text mode 

    compiled and run against "Qt 4.6 technology preview" takes

    Qt Code:
    1. creation of 30000 objects: 14.759 ms = 0.491933 us per object
    2. destruction of 30000 objects: 16.539 ms = 0.5513 us per object
    To copy to clipboard, switch view to plain text mode 

    whereas run under Qt-4.6 GA takes

    Qt Code:
    1. creation of 30000 objects: 18.028 ms = 0.6009 us per object
    2. destruction of 30000 objects: 2127.7 ms = 70.9234 us per object
    To copy to clipboard, switch view to plain text mode 

    But: if I don't connect the objects via parent-child, like here

    Qt Code:
    1. QObject *parent = new QObject;
    2. QObject **qls = new QObject*[COUNT];
    3. for(int i=0; i<COUNT; i++) {
    4. qls[i] = new QObject;
    5. }
    6.  
    7. for(int i=0; i<COUNT; i++) {
    8. delete qls[i];
    9. }
    To copy to clipboard, switch view to plain text mode 

    then I get excellent performance, even in the GA version:

    Qt Code:
    1. creation of 30000 objects: 9.654 ms = 0.321767 us per object
    2. destruction of 30000 objects: 14.067 ms = 0.468867 us per object
    To copy to clipboard, switch view to plain text mode 

    May be this is a bug which has no consequence in a UI application due to low amounts of objects and low response time expectancy during human interactions. I don't even know who to ask or where to go at Qt's website to open a ticket for that. ???

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Very slow QCoreApplication::removePostedEvents in Qt 4.6


Similar Threads

  1. Very slow repainting ofPixmaps in QGraphicsView images
    By drexiya in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2009, 18:13
  2. Qt4, slow on windows ?
    By eto.ethome.sk in forum Qt Programming
    Replies: 3
    Last Post: 28th May 2009, 00:34
  3. Why is drawText so terribly slow?
    By Ntoskrnl in forum Qt Programming
    Replies: 8
    Last Post: 1st August 2008, 19:15
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05

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
  •  
Qt is a trademark of The Qt Company.