Page 1 of 2 12 LastLast
Results 1 to 20 of 80

Thread: GraphicsView performance problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: GraphicsView performance problems

    I really suggest to recompile Qt with profiling information. You're shooting blind now. Profiling will give you the exact bottleneck point. Furthermore make sure your app is compiled correctly, I think you should be able to have a decomposition of the drawBackground() method in the profiling information as well. It should then tell you which part of the method takes most time and it should be possible to obtain without recompiling Qt.

  2. #2
    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: GraphicsView performance problems

    Quote Originally Posted by wysota View Post
    I really suggest to recompile Qt with profiling information. You're shooting blind now. Profiling will give you the exact bottleneck point. Furthermore make sure your app is compiled correctly, I think you should be able to have a decomposition of the drawBackground() method in the profiling information as well. It should then tell you which part of the method takes most time and it should be possible to obtain without recompiling Qt.
    ok finally I agree. You are right . I guess there is no decomposition because most method are inlined. Well I'll do that recompilation tomorrow(nice job in the weekend )
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #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: GraphicsView performance problems

    First do this (or something simmilar):
    Qt Code:
    1. void drawLines(QPainter *painter, QVarLengthArray<QLineF, 100> &lines){
    2. painter->drawLines(lines.data(), lines.size());
    3. }
    4.  
    5. void setupArray(QVarLengthArray<QLineF, 100> &lines){
    6. const int gridSize = 25;
    7. qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
    8. qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
    9. for (qreal x = left; x < rect.right(); x += gridSize)
    10. lines.append(QLineF(x, rect.top(), x, rect.bottom()));
    11. for (qreal y = top; y < rect.bottom(); y += gridSize)
    12. lines.append(QLineF(rect.left(), y, rect.right(), y));
    13. }
    14. void drawBackground(QPainter *painter, const QRectF &rect){
    15. painter->setPen(QPen(Qt::darkGreen,0));
    16. QVarLengthArray<QLineF, 100> lines;
    17. setupArray(lines);
    18. drawLines(painter, lines);
    19. }
    To copy to clipboard, switch view to plain text mode 

    This should allow you to measure how much time does it take to setup the array and how much to paint it.

  4. #4
    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: GraphicsView performance problems

    Quote Originally Posted by wysota View Post
    First do this (or something simmilar):
    Qt Code:
    1. void drawLines(QPainter *painter, QVarLengthArray<QLineF, 100> &lines){
    2. painter->drawLines(lines.data(), lines.size());
    3. }
    4.  
    5. void setupArray(QVarLengthArray<QLineF, 100> &lines){
    6. const int gridSize = 25;
    7. qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
    8. qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
    9. for (qreal x = left; x < rect.right(); x += gridSize)
    10. lines.append(QLineF(x, rect.top(), x, rect.bottom()));
    11. for (qreal y = top; y < rect.bottom(); y += gridSize)
    12. lines.append(QLineF(rect.left(), y, rect.right(), y));
    13. }
    14. void drawBackground(QPainter *painter, const QRectF &rect){
    15. painter->setPen(QPen(Qt::darkGreen,0));
    16. QVarLengthArray<QLineF, 100> lines;
    17. setupArray(lines);
    18. drawLines(painter, lines);
    19. }
    To copy to clipboard, switch view to plain text mode 

    This should allow you to measure how much time does it take to setup the array and how much to paint it.
    Ok I did that, the profile now says
    Flat profile:

    Each sample counts as 0.01 seconds.
    % cumulative self self total
    time seconds seconds calls Ts/call Ts/call name
    50.05 0.02 0.02 Node:: paint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*)
    25.03 0.03 0.01 GridScene::drawBackground(QPainter*, QRectF const&)
    25.03 0.04 0.01 Resistor::boundingRect() const
    0.00 0.04 0.00 192004 0.00 0.00 QVarLengthArray<QLineF, 100>::realloc(int, int)
    0.00 0.04 0.00 36506 0.00 0.00 GridScene::setupArray(QVarLengthArray<QLineF, 100>&, QRectF const&)
    0.00 0.04 0.00 36506 0.00 0.00 GridScene::drawLines(QPainter*, QVarLengthArray<QLineF, 100>&)
    0.00 0.04 0.00 1 0.00 0.00 global constructors keyed to _ZN9GridScene9drawLinesEP8QPainterR15QVarLengthArr ayI6QLineFLi100EE
    0.00 0.04 0.00 1 0.00 0.00 __static_initialization_and_destruction_0(int, int)
    Further

    Call graph (explanation follows)


    granularity: each sample hit covers 2 byte(s) for 24.97% of 0.04 seconds

    index % time self children called name
    <spontaneous>
    [1] 50.0 0.02 0.00 Node:: paint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*) [1]
    -----------------------------------------------
    <spontaneous>
    [2] 25.0 0.01 0.00 GridScene::drawBackground(QPainter*, QRectF const&) [2]
    0.00 0.00 36506/36506 GridScene::setupArray(QVarLengthArray<QLineF, 100>&, QRectF const&) [12]
    0.00 0.00 36506/36506 GridScene::drawLines(QPainter*, QVarLengthArray<QLineF, 100>&) [13]
    -----------------------------------------------
    <spontaneous>
    [3] 25.0 0.01 0.00 Resistor::boundingRect() const [3]
    -----------------------------------------------
    0.00 0.00 192004/192004 GridScene::setupArray(QVarLengthArray<QLineF, 100>&, QRectF const&) [12]
    [11] 0.0 0.00 0.00 192004 QVarLengthArray<QLineF, 100>::realloc(int, int) [11]
    -----------------------------------------------
    0.00 0.00 36506/36506 GridScene::drawBackground(QPainter*, QRectF const&) [2]
    [12] 0.0 0.00 0.00 36506 GridScene::setupArray(QVarLengthArray<QLineF, 100>&, QRectF const&) [12]
    0.00 0.00 192004/192004 QVarLengthArray<QLineF, 100>::realloc(int, int) [11]
    -----------------------------------------------
    0.00 0.00 36506/36506 GridScene::drawBackground(QPainter*, QRectF const&) [2]
    [13] 0.0 0.00 0.00 36506 GridScene::drawLines(QPainter*, QVarLengthArray<QLineF, 100>&) [13]
    -----------------------------------------------
    0.00 0.00 1/1 __do_global_ctors_aux [25]
    [14] 0.0 0.00 0.00 1 global constructors keyed to _ZN9GridScene9drawLinesEP8QPainterR15QVarLengthArr ayI6QLineFLi100EE [14]
    0.00 0.00 1/1 __static_initialization_and_destruction_0(int, int) [15]
    -----------------------------------------------
    0.00 0.00 1/1 global constructors keyed to _ZN9GridScene9drawLinesEP8QPainterR15QVarLengthArr ayI6QLineFLi100EE [14]
    [15] 0.0 0.00 0.00 1 __static_initialization_and_destruction_0(int, int) [15]
    -----------------------------------------------
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #5
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    [2] 25.0 0.01 0.00 GridScene::drawBackground(QPainter*, QRectF const&) [2]
    0.00 0.00 36506/36506 GridScene::setupArray(QVarLengthArray<QLineF, 100>&, QRectF const&) [12]
    0.00 0.00 36506/36506 GridScene::drawLines(QPainter*, QVarLengthArray<QLineF, 100>&) [13]
    That looks really weird.
    The reason probably once again that the time is spent inside of Qt-Code and not yours, so sadly that does not help.
    Or it could have been inlined, again not really helpfull :-/


    Have you tried valgrind/callgrind and KCacheGrind as a profiler? It is rather nice :-)
    Last edited by camel; 17th February 2007 at 14:41.

  6. #6
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    That looks really weird.
    The reason probably once again that the time is spent inside of Qt-Code and not yours, so sadly that does not help.
    These figures are wrong. All functions from inside Qt should be counted on behalf of the functions calling them and here all functions have nothing but zeros. The application needs to run longer.

    Or it could have been inlined, again not really helpfull :-/
    Yes, that's possible, especially if they were implemented inside the class header and optimisations were enabled.

    You must be sure to disable inlining optimisations. You can use -fno-inline to disable inlining.

  7. #7
    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: GraphicsView performance problems

    Yup! you both are right. Anyway I am recompiling Qt tomorrow. I'll surely post after I do that. In the meanwhile I'd like to inform you people that I have never used cachegrind. Is that better than gprof ? If yes how should I use that ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  8. #8
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Did you try my last modification? Did it change anything for you?

    Quote Originally Posted by Gopala Krishna View Post
    Yup! you both are right. Anyway I am recompiling Qt tomorrow. I'll surely post after I do that. In the meanwhile I'd like to inform you people that I have never used cachegrind. Is that better than gprof ? If yes how should I use that ?
    You do not need to compile anything special (besides DEBUG of course ;-)

    Then call
    $valgrind --tool=callgrind ./YOUR_APP
    this will produce a file called callgrind.out.PID_OF_PROCESS

    then you can call
    $kcachegrind callgrind.out.PID_OF_PROCESS
    http://kcachegrind.sourceforge.net/cgi-bin/show.cgi

  9. #9
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    Did you try my last modification? Did it change anything for you?



    You do not need to compile anything special (besides DEBUG of course ;-)

    Then call


    this will produce a file called callgrind.out.PID_OF_PROCESS

    then you can call


    http://kcachegrind.sourceforge.net/cgi-bin/show.cgi
    Thanks ! Here is the output as attachment
    EDIT: My quota of attachment is almost over. I'll update a bit later.
    Last edited by Gopala Krishna; 17th February 2007 at 15:34. Reason: updated contents
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  10. #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: GraphicsView performance problems

    I have modified my application which uses QGraphicsView framework to draw a grid simmilar to yours and I implemented it in a worst possible way:
    Qt Code:
    1. void drawBackground ( QPainter * painter, const QRectF & rect ){
    2. static QPen p(QColor(150,150,150));
    3. painter->setPen(p);
    4. for(int row=10+((int)(rect.top())/10)*10; row<rect.bottom(); row+=10){
    5. for(int col = 10+((int)(rect.left())/10)*10; col<rect.right(); col+=10)
    6. painter->drawPoint(col, row);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Profiling info (compiled with -fno-inline -ggdb -pg) looks like this:
    text Code:
    1. % cumulative self self total
    2. time seconds seconds calls us/call us/call name
    3. 33.33 0.02 0.02 1547664 0.01 0.01 QRectF::right() const
    4. 33.33 0.04 0.02 SpecScene::drawBackground(QPainter*, QRectF const&)
    5. 16.67 0.05 0.01 1527572 0.01 0.01 QPainter::drawPoint(int, int)
    To copy to clipboard, switch view to plain text mode 
    As you see 33% of the application time is spent in drawBackground and half of it is used to calculate QRectF::right() (which makes sense as it gets calculated in each iteration of the loop) and pretty much is used to actually draw the points.

    text Code:
    1. index % time self children called name
    2. <spontaneous>
    3. [1] 83.3 0.02 0.03 SpecScene::drawBackground(QPainter*, QRectF const&) [1]
    4. 0.02 0.00 1547627/1547664 QRectF::right() const [2]
    5. 0.01 0.00 1527572/1527572 QPainter::drawPoint(int, int) [3]
    6. 0.00 0.00 20635/20651 QRectF::bottom() const [35]
    7. 0.00 0.00 20055/20055 QRectF::left() const [36]
    8. 0.00 0.00 580/580 QRectF::top() const [93]
    9. 0.00 0.00 1/702 QColor::QColor(int, int, int, int) [92]
    To copy to clipboard, switch view to plain text mode 
    As you see it is actually more time consuming to calculate the rectangle coords than to draw points!

    Some facts:
    - I use Qt4.2.2 on i686 Linux,
    - I didn't use antialiasing,
    - I didn't use scaling (so I have an identity matrix when it comes to viewport-window transformations),
    - scene size was about 1200x1000,
    - I didn't compile Qt with profiling information (so I guess it's not required after all),
    - I got detailed info about both mine and Qt methods,
    - the result is pretty fast.

    I got a pretty good result, but I didn't suffer from viewport-window transformations which might be your case if you scale the view. I didn't use antialiasing for my view, as points are points - they don't suffer from the aliasing effect. I could easily improve the implementation by calculating rectangle coordinates once per drawBackground() which should reduce the execution effort by half.

    It is up to you to do the interpretation of the results. My impression is that it is not really drawBackground() which causes the slowdown - maybe it is just called too often by other parts of the system? Maybe you abuse update()?

  11. #11
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Quote Originally Posted by wysota View Post
    I have modified my application which uses QGraphicsView framework to draw a grid simmilar to yours and I implemented it in a worst possible way:

    Profiling info (compiled with -fno-inline -ggdb -pg) looks like this:
    text Code:
    1. % cumulative self self total
    2. time seconds seconds calls us/call us/call name
    3. 33.33 0.02 0.02 1547664 0.01 0.01 QRectF::right() const
    4. 33.33 0.04 0.02 SpecScene::drawBackground(QPainter*, QRectF const&)
    5. 16.67 0.05 0.01 1527572 0.01 0.01 QPainter::drawPoint(int, int)
    To copy to clipboard, switch view to plain text mode 
    Well, if you disable inlining, no wonder right() is expensive. calling a function 1.5 Million times just takes its time...inlining is there for a reason ;-)

    So I would not call this run very exemplary... :-)

  12. #12
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    just a note:
    If you like to profile further into the drawing part,
    you need to call:
    valgrind --tool=callgrind --seperate-callers=5 --seperate-recs=10 ./YOUR_APP
    Otherwise you will get "cycles", which is not very helpfull in this task..

    BUT: this takes up much more memory to analyze later...

  13. #13
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Hi,

    well I just love to play with this... ;-)


    Here is another (and much faster) way to write the drawBackground function...with the added niceness that it helps avoiding the color errors ;-)

    You might want to check if this survives zooming etc.

    Qt Code:
    1. void drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. const int gridSize = 25;
    4.  
    5. if (backgroundCache.isNull()) {
    6. backgroundCache = QPixmap(gridSize, gridSize);
    7. const int middle = gridSize / 2;
    8. QPainter backgroundPainter(&backgroundCache);
    9. backgroundPainter.setRenderHints(painter->renderHints());
    10. backgroundPainter.fillRect(QRect(0, 0, gridSize, gridSize), QBrush(Qt::white));
    11. backgroundPainter.setPen(backgroundPen);
    12. backgroundPainter.setBrush(backgroundBrush);
    13. backgroundPainter.drawLine(0, middle, gridSize, middle);
    14. backgroundPainter.drawLine(middle, 0, middle, gridSize);
    15. }
    16.  
    17. const int realLeft = static_cast<int>(std::floor(rect.left()));
    18. const int realRight = static_cast<int>(std::ceil(rect.right()));
    19. const int realTop = static_cast<int>(std::floor(rect.top()));
    20. const int realBottom = static_cast<int>(std::ceil(rect.bottom()));
    21.  
    22.  
    23. const int firstLeftGridLine = realLeft - (realLeft % gridSize);
    24. const int firstTopGridLine = realTop - (realTop % gridSize);
    25.  
    26.  
    27. QPainterPath background;
    28. for (int x = firstLeftGridLine; x < realRight; x += gridSize) {
    29. for (int y = firstTopGridLine; y < realBottom; y += gridSize) {
    30. painter->drawPixmap(x, y, backgroundCache);
    31. }
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    Have a nice day :-)
    Last edited by camel; 17th February 2007 at 16:26.

  14. The following user says thank you to camel for this useful post:

    Gopala Krishna (17th February 2007)

  15. #14
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    Hi,

    well I just love to play with this... ;-)


    Here is another way to write the drawBackground function...with the added niceness that it helps avoiding the color errors ;-)

    You might want to check if this survives zooming etc.

    Qt Code:
    1. void drawBackground(QPainter *painter, const QRectF &rect)
    2. ...
    To copy to clipboard, switch view to plain text mode 

    Have a nice day :-)
    Not bad idea! That problem solved !!! Thanks a lot.
    Now the next problem is performance !
    A good day to you too
    Last edited by Gopala Krishna; 17th February 2007 at 16:32. Reason: updated contents
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  16. #15
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    just a note:
    If you like to profile further into the drawing part,
    you need to call:


    Otherwise you will get "cycles", which is not very helpfull in this task..

    BUT: this takes up much more memory to analyze later...
    I get the following error
    valgrind: Bad option '--seperate-callers=5'; aborting.
    I am trying to analyse the code as it is now. I am getting lost here and there but kcachegrind is a cool tool. Needs some time to get used to it. Thanks for helping me till now. I'll continue with this tomorrow.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  17. #16
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Quote Originally Posted by Gopala Krishna View Post
    I get the following error
    valgrind: Bad option '--seperate-callers=5'; aborting.
    I think they changed the option names during 3.1 and 3.2 (which I use)

    try:
    valgrind --tool=callgrind --fn-caller=5 --fn-recursion=10 ./YOUR_APP

  18. #17
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    Well, if you disable inlining, no wonder right() is expensive. calling a function 1.5 Million times just takes its time...inlining is there for a reason ;-)

    So I would not call this run very exemplary... :-)
    It means that QRectF::right() takes longer than QPainter::drawPoint() and right() is not a very complex method

    After getting rid of the right() and bottom() calls inside the loop the result of profiling is as follows:
    text Code:
    1. 50.00 0.06 0.06 SpecScene::drawBackground(QPainter*, QRectF const&)
    2. 25.00 0.09 0.03 1460235 0.02 0.02 QPoint::QPoint(int, int)
    3. 16.67 0.11 0.02 1454915 0.01 0.03 QPainter::drawPoint(int, int)
    To copy to clipboard, switch view to plain text mode 

    The QPoint constructor is called by QPainter::drawPoint, so we can forget about it. The whole method takes over 90% of the whole application time and gives a total of less than 0.1s. That's not much

    It is important to see what the bottleneck is instead of shooting blind. No matter how much you optimise QPainter::drawLines() if it's not the bottleneck, you won't get a decent improvement.

    In my opinion it would be much simpler and faster to simply apply a backgroundBrush with the grid to the scene and forget about points and lines. You wouldn't get any painter paths then, no floating point operations. The only thing that could slow down the process is the matrix transformation, so try to avoid it.

  19. #18
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView performance problems

    Quote Originally Posted by wysota View Post
    It is important to see what the bottleneck is instead of shooting blind. No matter how much you optimise QPainter::drawLines() if it's not the bottleneck, you won't get a decent improvement.
    That is why I look into my KCachgrind and follow the callgraph and sources ;-)

    The problem is not drawPoints, as that does not do much.

    The problem with drawLines and friends is that it often (with antialiasing) first creates a painterpath from those lines and then paints them. This takes time, not least because of memory allocation.

    This is why I said use painterpaths directly.

    Optimizing the returnvalue of boundingrect and shape is so easy (and makes the code much nicer in my opinion) so that I would not even consider it a optimization, its just nicer programming. (besides helping during run-time of course ;-)

    Quote Originally Posted by wysota View Post
    In my opinion it would be much simpler and faster to simply apply a backgroundBrush with the grid to the scene and forget about points and lines. You wouldn't get any painter paths then, no floating point operations. The only thing that could slow down the process is the matrix transformation, so try to avoid it.
    I cuncur there, see my last post about the drawbackground function.
    To use a background brush would be the logical next step ;-)

  20. #19
    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: GraphicsView performance problems

    Quote Originally Posted by camel View Post
    The problem with drawLines and friends is that it often (with antialiasing) first creates a painterpath from those lines and then paints them. This takes time, not least because of memory allocation.

    This is why I said use painterpaths directly.
    If you disable antialiasing, there is a possibility that painter paths will not be used. And there is no point in having antialiasing enabled for drawing horizontal or vertical lines, as these don't suffer from the aliasing effect. You can safely temporarily disable antialiasing while painting those.
    Qt Code:
    1. bool isAA = painter->renderHints() & QPainter::Antialiasing;
    2. painter->setRenderHint(QPainter::Antialiasing, false);
    3. painter->drawLines(...);
    4. painter->setRenderHint(QPainter::Antialiasing, isAA);
    To copy to clipboard, switch view to plain text mode 

    Another possibility of painter paths being active is that there is scaling involved. But while zooming in, the number of lines needed to draw should decrease. While zooming out on the other hand you can draw fewer lines as too many of them will clutter the scene anyway.

    You can also store the path in a member variable and then only draw the path on the painter. But I think using a background brush will be much faster, especially with smooth scaling disabled.

  21. #20
    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: GraphicsView performance problems

    Quote Originally Posted by wysota View Post
    In my opinion it would be much simpler and faster to simply apply a backgroundBrush with the grid to the scene and forget about points and lines.
    Well I tried even this. That is not the problem. First of all the main problem is while moving "many items" together. For example in the above eg the performance goes down if you select all resistors and move - thats about 80 items at a time!!! (20 resistors,40 nodes, 20 text items) . Here to get sufficient performance the area to be updated should be selected appropriately and efficiently so that the scene is updated least number of times.

    Further I have a question - is the the bsp indexing causing these performance problems ?

    Further I would like to inform that I am not using any matrix transformations. All these are just on regular matrix.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  2. QT GraphicsView Help
    By mistertoony in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2007, 04:17
  3. Replies: 1
    Last Post: 4th October 2006, 16:05
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. Increasing performance from Qtextedit, listview, etc?
    By taylor34 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:20

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.