Results 1 to 12 of 12

Thread: Qt3 more fast than Qt4 ?

  1. #1
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    2

    Default Qt3 more fast than Qt4 ?

    Hello,

    I created an application that draws 10000 lines in canvas, it allows to move the lines with the mouse.

    Qt3 works well but Qt4 is slow.
    I enabled Opengl with Qt4 but is more slow than whitout.

    I attache a zip with 2 versions (qt3 and qt4).

    is Qt3 more fast than Qt4 ?

    Thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: Qt3 more fast than Qt4 ?

    Sometimes yes, sometimes no. The two APIs QCanvas and Graphics View are similar enough in behavior and API to be compared like this, that's only reasonable. But the same code might not be as fast in one as the other, although often tweaking the slow one will bring them up to the same level. This is no exception.

    In your example, you've got 10000 line items on top of each other. This is the absolute worst-case scenario for a BSP tree, which is what Graphics View uses for indexing. If you run a profiler, it'll show that most of the time is spent in the BSP tree.

    First, the fastest the program can start, show itself, and then quit, is today 4.5 seconds on my machine using Qt 4.3. With Qt 3.3, this is 1.2 seconds. Now,

    Qt Code:
    1. scene.setBspTreeDepth(6); // seems to be optimal for your app
    To copy to clipboard, switch view to plain text mode 

    Now it takes only 0.8 seconds with 4.3, a 5.6x speedup. That's 50% faster than Qt 3. You should notice right away that the Qt 4 app starts faster than the Qt 3 one.

    Now, you're creating lines that have a width of 1. In Qt 3, line items were just drawn as cosmetic lines (startpoint, endpoint). In Qt 4, line items follow the same capping rules as QPainter lines, and they transform properly. Try zooming in in the Qt 3 example, you'll see the lines don't get any thicker, but in Qt 4 they do. Their shape gets slightly more complex with Qt 4 also, because the shape of a line in Qt 4 is 100% accurate, whereas in Qt 3 a QCanvasLine's area was only estimated roughly. Try setting a cosmetic pen instead of a normal pen in Qt 4:

    Qt Code:
    1. i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 0) );
    2. // notice pen width == 0
    To copy to clipboard, switch view to plain text mode 

    Because the cosmetic pen shape is so simple, and this is equivalent to QCanvas' behavior, you get close to a 10x speedup. Now the example runs at approximately the same speed in Qt 4 as in Qt 3.

    There's still some things that can be optimized further in Qt 4, your example serves as a very nice benchmark. If you still find the example is slow, do like me and run a profiler on it (I recommend valgrind --tool=callgrind, and kcachegrind for visualizing the results).
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  3. The following 2 users say thank you to Bitto for this useful post:

    commarmi (14th September 2007), Gopala Krishna (14th September 2007)

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

    Default Re: Qt3 more fast than Qt4 ?

    Andreas, I admit - this is a very nice piece of explanation. Trolltech should do some trainings in Qt internals and quirks, not only demonstrating the API. Do you intend to show such things as the one above during DevDays (sorry for the offtopic)?

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt3 more fast than Qt4 ?

    Quote Originally Posted by wysota View Post
    Andreas, I admit - this is a very nice piece of explanation.
    But of course it is. The man wrote the damn thing, didn't he?

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

    Default Re: Qt3 more fast than Qt4 ?

    Quote Originally Posted by marcel View Post
    But of course it is. The man wrote the damn thing, didn't he?
    That's not the point. The point is he is willing to share his knowledge. Of course we could browse the sources, etc. but that takes time and he already knows the sources by heart

  7. #6
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt3 more fast than Qt4 ?

    I'll try to find some time to talk about making things fast, but it's pretty hard to generalize on it since it's so specific to the application at hand :-). Still, it's a 2.5h talk... there should be some room for it. I also try to update the documentation whenever I come across benchmark apps like this, too. Nobody likes hidden slowness, or "fastness" for that matter...
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  8. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt3 more fast than Qt4 ?

    Quote Originally Posted by Bitto View Post
    Sometimes yes, sometimes no. The two APIs QCanvas and Graphics View are similar enough in behavior and API to be compared like this, that's only reasonable. But the same code might not be as fast in one as the other, although often tweaking the slow one will bring them up to the same level.
    But both sit on a QPainter. In Qt3 QPainter was a thin wrapper around the native graphics library ( X1, ...), in Qt4 we run through Arthurs render pipeline.

    Although the performance of Qt4 has been improved a lot from Qt 4.0, Qt4 applications feel fat. ( F.e. when scrolling an empty scroll area, the handle of the scroll bar can't follow mouse movements. ) The new release of our product has recently been ported to Qt4, what makes it possible to compare - and the result is not very appealing.

    I remember a discussion at the first Trolltech Days, where I was told, that the effects of modern desktops have priority and the performance issues will be obsolete, because of hardware improvements. But today people (including me) are looking for fanless, less power consuming office systems.

    Uwe

  9. #8
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    2

    Default Re: Qt3 more fast than Qt4 ?

    Thanks Bitto for your help.

    Really now is more fast.

  10. #9
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    2

    Default Re: Qt3 more fast than Qt4 ?

    But,

    why with opengl is more slow ? I'm testing on:
    Pentium4 1.70GHz
    1Gb of Ram
    GeForce4 MX 440 AGP 8x

    Gentoo Linux 2007.0
    xorg 1.3.0
    NVIDIA Linux x86 Kernel Module 1.0-9639
    glxgears = "1181.034 FPS"

    only add "setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)))" on my code. Is it correct ?

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

    Default Re: Qt3 more fast than Qt4 ?

    Quote Originally Posted by Uwe View Post
    But both sit on a QPainter. In Qt3 QPainter was a thin wrapper around the native graphics library ( X1, ...), in Qt4 we run through Arthurs render pipeline.

    Although the performance of Qt4 has been improved a lot from Qt 4.0, Qt4 applications feel fat. ( F.e. when scrolling an empty scroll area, the handle of the scroll bar can't follow mouse movements. ) The new release of our product has recently been ported to Qt4, what makes it possible to compare - and the result is not very appealing.
    I think you can tweak around things a little, disabling the backing store, for instance. I'm currently experimenting with a simple animated widget and disabling composition caused a vast improvement in cpu usage (though it was the X server that reported high usage, not the application itself). I guess there are more improvements to be applied, it's just not that obvious where they are. That's why a training like the one I mentioned could be helpful.

    Besides that, computers change and we, the developers, have to adjust to that. Multicore processors are becoming standard nowadays, but an application has to be specially designed to make use of the technology. Otherwise it'll run slower instead of being faster due to the way multi-core works.

  12. #11
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt3 more fast than Qt4 ?

    OpenGL requires you to redraw everything in the viewport always. There's no such thing as a partial update, scroll optimization, and so on. So with a native painter, when you scroll horizontally the only area that's redraw is the 1-pixel vertical line at the right-most or left-most part of your viewport. The rest is just shifted. This isn't possible with QGLWidget - every time something changes, everything is redrawn.

    Why QGLWidget cannot draw 10000 lines at real-time / 25fps, should just be a matter of running a profiler though. I'm sure something will show up that will point you in the right direction.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  13. The following user says thank you to Bitto for this useful post:

    commarmi (14th September 2007)

  14. #12
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    2

    Default Re: Qt3 more fast than Qt4 ?

    Ok, thanks.

    I will compile Qt with debug info and run profiler.

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. Are fast reg exps too much to ask?
    By fullmetalcoder in forum Qt Programming
    Replies: 10
    Last Post: 15th June 2007, 21:02
  3. Fast serialization/deserialization
    By fullmetalcoder in forum Qt Programming
    Replies: 22
    Last Post: 9th May 2007, 12:58
  4. Replies: 6
    Last Post: 8th January 2007, 10:24
  5. Fast Keyboard, help !
    By Alex63 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2006, 18:18

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.