Results 1 to 12 of 12

Thread: again QGraphicsView performance

  1. #1
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default again QGraphicsView performance

    Hi

    I like QGraphicsView very much, but I vave some issue with performance. I used to search help on forums histroy but I still need some help.

    On my scene I have a video some CLVideoWindow’s items ihereted from QGraphicsItem. Basicly each CLVideoWindow object dispaying live video ( video size is about 800x60, so boundingRect returns QRectF(0,0,800,600).

    void CLVideoWindow:aint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) function does some OpenGL shaders.

    So, as you can see my items is preaty dynamic. I need to call item->update() function in gui thread ~20-30 times per second for each item.

    And it works fine with 2 itimes, but as soon as I add third item on the scene gui thread cpu usage jumps form 6-8% up to 30-36%. Threre is no differences beween 1 2 and 3 items ( they just display different video content ).

    Problem is not in CLVideoWindow:aint function. Even if I do not do anything inside paint(…) ( just return ) gui thread takes almost the same CPU time. If I do not call update() so ofen – it’s fine ( low cpu usage ).

    The problem apears only if I add third item(no metter in what sequence). I also noticed that if I maximize application gui thread also takes more CPU ( but not always ).

    After I add 4,5,6.. items cpu increased on 4-5% ( this is expactable ). But how come third item gives such dramatic increase?

    I have QT.4.5.2 Windows Xp / Vista.


    Here are options I use for my QGraphicsView( I do not use Antialiasing):

    Qt Code:
    1. m_View.setViewport(new QGLWidget());
    2.  
    3. m_View.setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
    4.  
    5. m_View.setCacheMode(QGraphicsView::CacheBackground);
    6.  
    7.  
    8. m_View.setDragMode(QGraphicsView::ScrollHandDrag);
    9.  
    10. m_View.setOptimizationFlag(QGraphicsView::DontClipPainter);
    11. m_View.setOptimizationFlag(QGraphicsView::DontSavePainterState);
    12. m_View.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
    13.  
    14. m_View.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    15. m_View.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    To copy to clipboard, switch view to plain text mode 



    Thank you in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: again QGraphicsView performance

    I would make sure all your updates are synchronized and I'd probably switch to FullViewportUpdate then to minimize the number of paint events you are going to get (although you are using a GL viewport, so it's already doing full viewport updates but nevertheless, it's worth to try). Apart from that it's best to run your application through a profiler to see where the bottleneck is. It's hard to improve performance if you don't know what is causing the slowdowns.
    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
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    I'm sure that my updates are synchronized. All them called from gui thread. Some other threads just emits signal to call update function from gui.

    My Intel Vtune profiler crashes with this application-( I'll try to use different one.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: again QGraphicsView performance

    Quote Originally Posted by medved6 View Post
    I'm sure that my updates are synchronized.
    How do you know that?

    All them called from gui thread.
    Which doesn't mean they are synchronized. I'm not talking about threads but about doing a single update of your view instead of three.
    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.


  5. #5
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    Which doesn't mean they are synchronized. I'm not talking about threads but about doing a single update of your view instead of three.[/QUOTE]

    Ok. How can I know/check that ?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: again QGraphicsView performance

    If you didn't do anything to synchronize updates then they are probably not synchronized. You need to make sure all items are updated upon the same timeout from the same timer.
    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.


  7. #7
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    I see what you mean. It is better to call as much updates as possible per one time..., not separately.

    In my apps it works like this... For each video window I have it's own thread. This thread decodes video comming from some quue, and calls some signal. The slot for that signal is function im gui thread, calling update().
    Some video has 20.5 fps, some 33.67fps, some 4.5 fps... Video shoud be displayed smooth.
    So I'm not sure can I synchronize updates.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: again QGraphicsView performance

    Use a timer to synchronize updates.
    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.


  9. #9
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    I said I can not. I need to draw image as soon as possible, do not wait.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: again QGraphicsView performance

    In that case you have to live with big cpu usage. You can't eat a pie and still have the pie. You either show all images at the same moment of time or not. If not then you have to redraw the same image many times hence slowing down the application. By the way, I'm sure that if you display the camera image 5ms later than "immediately" nobody would notice. But suit yourself.
    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.


  11. The following user says thank you to wysota for this useful post:

    medved6 (21st December 2009)

  12. #11
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    Ok. Thank you for the advice! I'll see if it helps, it's easy to try.
    Let you know here. Thank you again!

  13. #12
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: again QGraphicsView performance

    Thank you.
    You advice about update synchronization was very helpfull. The problem is solved.
    Now I have linear increment of CPU usage with every new video. No metter how many cams do I have I do updates ( if needded ) at one shot every 25 ms.

Similar Threads

  1. QGraphicsView and panning performance
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2009, 19:40
  2. QGraphicsView performance in 4.6
    By Lodorot in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2009, 23:09
  3. Replies: 1
    Last Post: 16th September 2009, 11:23
  4. QGraphicsView animation performance
    By rakkar in forum Newbie
    Replies: 8
    Last Post: 3rd September 2009, 04:14
  5. QGraphicsView performance
    By Halabund in forum Newbie
    Replies: 3
    Last Post: 17th April 2009, 10:12

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.