Page 4 of 4 FirstFirst ... 234
Results 61 to 72 of 72

Thread: QGraphicsScene/QGraphicsView performance problems

  1. #61
    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: QGraphicsScene/QGraphicsView performance problems

    Disabling the index will make it harder to detect which items to draw without any benefit from disabling it. As the items don't move the use of an index doesn't cause any overhead.

    What is important is to divide the "field" item into "subfield" and "subsubfield" items, so that indexing can show its power. The field itself is cheap to draw because you don't really draw anything but drawing all subitems instead of the set that is really visible yields a huge overhead.

  2. #62
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene/QGraphicsView performance problems

    My first attempt to subclass QGraphicsItem into FieldItem, SubFieldItem and ShapeItem and use them in a parent-child sceme gave even worse performance and memory consumption than using QGraphicsRectItem.
    I will prepare the test project I posted before to use the parent-child item strategy and post it later so anyone interested can have a look and see where I am going wrong.
    MacOSX user dabbling with Linux and Windows.

  3. #63
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene/QGraphicsView performance problems

    Is there any advantage to use integers (QRect, QPoint, etc.) instead of floats (QRectF, QPointF, etc. ) regarding drawing performance?
    MacOSX user dabbling with Linux and Windows.

  4. #64
    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: QGraphicsScene/QGraphicsView performance problems

    Yes, it's faster using ints when drawing. Calculations should be more or less equally fast. But in your case the overhead shouldn't be large. Of course it's wise to use either int or real variants depending on the level of detail.

  5. #65
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene/QGraphicsView performance problems

    Back again...

    Here are two test projects with pattern simulation, one "flat" where the items are fields and the painter draws subfields and pattern shapes from a linked list, stored in each field object, and one "hieararcic" where the top items are fields and the subfields are childs to the fields and the pattern shapes are childs to the subfields.

    The "flat"version is lean on memory and draws the simulated pattern very fast, 100,000 micron chipsize is no problem.
    The "hierachic" version draws a lot of memory, and a chipsize of 50,000 can barely be drawn.

    Please comment on these test apps, please suggest how the "hierarchic" version may be improved. I suspect that the "flat" version is fine for the simulated pattern, but may suffer for a real datafile if there is a lot of data in one field.

    I noticed that there is a dramatic difference in performance if the item is using a small "local" size and placed by setPos() rather than having a "global" bounding box with large minimum and maximum numeric values. Example min=(0,0) max=(100,100) and setPos(10000,10000) vs. min =(10000,10000) max=(10100,10100) and no setPos.
    Can you explain why?
    Attached Files Attached Files
    MacOSX user dabbling with Linux and Windows.

  6. #66
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene/QGraphicsView performance problems

    It does work on my system now and i still recommend the flat one as you can easily finetune the drawings of subfields (lod)
    BTW zooming onto single subfield almost hangs your app on my system. Does it work smooth for you ?

    Also as far as i could see you are directly representing the logical sizes as "onscreen" display size.
    For eg with chipsize=50000
    FieldSize= QSize(32000,32000)
    SubFieldSize= QSize(4000,4000)

    And you are using this size for each item!

    If you need more optimization and if it is possible, do scale down each of these so that on screen "transformation free" size of each item is within (500,500). It is far easier to just multiply the coord by scale factor and then display in sidebar than actually drawing the item in those huge sizes!

    Otherwise you can also try to use QStyleOptionGraphicsItem::exposedRect in FieldItem:: paint method and draw only visible part. But i guess this is quite hard and might not work as required.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  7. #67
    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: QGraphicsScene/QGraphicsView performance problems

    I made my own experiments. With about 0.5M items the application was using about 80 megabytes of memory which gives an average of 160 bytes per item (including the memory used by all other components) which I think is not that bad. At that point the application was responsive although very slow. The slowdown is caused by the fact that even if I intend not to draw some item, the matrix still has to be produced and applied for each of them. Making the architecture ignore items that are sure not to be drawn would speed the app significantly.

    See attached the code I used.
    Attached Files Attached Files

  8. #68
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene/QGraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    It does work on my system now and i still recommend the flat one as you can easily finetune the drawings of subfields (lod)
    BTW zooming onto single subfield almost hangs your app on my system. Does it work smooth for you ?
    This is a bug in Qt4.3, probably Linux-specific, will be fixed in Qt4.4.
    I tried the Qt4.4 snapshot, and with this it is ok.
    Also as far as i could see you are directly representing the logical sizes as "onscreen" display size.
    For eg with chipsize=50000
    FieldSize= QSize(32000,32000)
    SubFieldSize= QSize(4000,4000)

    And you are using this size for each item!

    If you need more optimization and if it is possible, do scale down each of these so that on screen "transformation free" size of each item is within (500,500). It is far easier to just multiply the coord by scale factor and then display in sidebar than actually drawing the item in those huge sizes!
    Unless there is a problem using large numbers, I find it an advantage to use integers with full internal data resolution. It is sometimes of interest to have the cursor position to show the exact position in the drawing. Int's also give a slight drawing performance advantage, right?
    Otherwise you can also try to use QStyleOptionGraphicsItem::exposedRect in FieldItem:: paint method and draw only visible part. But i guess this is quite hard and might not work as required.
    I will look into this.
    MacOSX user dabbling with Linux and Windows.

  9. #69
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene/QGraphicsView performance problems

    Quote Originally Posted by wysota View Post
    I made my own experiments. With about 0.5M items the application was using about 80 megabytes of memory which gives an average of 160 bytes per item (including the memory used by all other components) which I think is not that bad. At that point the application was responsive although very slow. The slowdown is caused by the fact that even if I intend not to draw some item, the matrix still has to be produced and applied for each of them. Making the architecture ignore items that are sure not to be drawn would speed the app significantly.
    Will this be someting for a future Qt release?
    See attached the code I used.
    I will study the code, I will probably learn a lot from it. Thanks!
    MacOSX user dabbling with Linux and Windows.

  10. #70
    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: QGraphicsScene/QGraphicsView performance problems

    Quote Originally Posted by bnilsson View Post
    Will this be someting for a future Qt release?
    I don't think Andreas' team has such plans You'd have to implement it yourself by reimplementing drawItems() in the scene (I think).

  11. #71
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene/QGraphicsView performance problems

    Quote Originally Posted by wysota View Post
    Making the architecture ignore items that are sure not to be drawn would speed the app significantly.
    Is it true ? or did i misunderstand ?
    I was under impression that GV framework doesn't draw items not visible on viewport (ofcourse i dont mean hidden items)
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  12. #72
    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: QGraphicsScene/QGraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    I was under impression that GV framework doesn't draw items not visible on viewport (ofcourse i dont mean hidden items)
    Take a look at my code. I'm deciding whether to draw something or not based on the distance between the object and the camera (level of detail). If something is very far away (but still inside the camera's viewport) I decide not to draw it, but the whole painting environment is set up by the architecture anyway.

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  2. Poor performance with Qt 4.3 and Microsoft SQL Server
    By Korgen in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 10:28
  3. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 17:32
  4. Replies: 2
    Last Post: 8th March 2007, 22:22
  5. Replies: 1
    Last Post: 4th October 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.