PDA

View Full Version : slowness QGraphicsView setScene



rk123
31st March 2010, 19:48
Hello,

I was trying to implement a design using Graphics View/Scene method. I am seeing a lot of time being consumed in QGraphicsView::setScene
To reproduce in a QT known code,
I changed the chip demo as follows mainwindow.cpp
93c93
< for (int i = -11000; i < 11000; i += 110) {
---
> for (int i = -110000; i < 110000; i += 110) {
96c96
< for (int j = -7000; j < 7000; j += 70) {
---
> for (int j = -70000; j < 70000; j += 70) {
98,99c98,99
< qreal x = (i + 11000) / 22000.0;
< qreal y = (j + 7000) / 14000.0;
---
> qreal x = (i + 110000) / 22000.0;
> qreal y = (j + 70000) / 14000.0;

I made the data much bigger. Now, I see the following stack:
#0 0x0000000000981a3f in qt_closestItemFirst ()
#1 0x000000000095ab58 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#2 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#3 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#4 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#5 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#6 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#7 0x000000000095abf3 in QAlgorithmsPrivate::qSortHelper<QList<QGraphicsItem*>::iterator, QGraphicsItem*, bool (*)(QGraphicsItem const*, QGraphicsItem const*)> ()
#8 0x0000000000985fdc in QGraphicsSceneBspTreeIndexPrivate::sortItems ()
#9 0x0000000000986ab9 in QGraphicsSceneBspTreeIndex::items ()
#10 0x00000000009677aa in QGraphicsScene::items ()
#11 0x0000000000968f5e in QGraphicsScene::itemsBoundingRect ()
#12 0x0000000000969167 in QGraphicsScene::sceneRect ()
#13 0x00000000009928d2 in QGraphicsView::sceneRect ()
#14 0x000000000099293a in QGraphicsViewPrivate::recalculateContentSize ()
#15 0x0000000000993a6c in QGraphicsView::setScene ()
#16 0x0000000000431607 in MainWindow::MainWindow ()
#17 0x0000000000431297 in main ()

Any ideas on what I am doing wrong? I am using qt-everywhere-opensource-src-4.6.1

Thanks -- RK

wysota
31st March 2010, 19:56
What exactly is the problem? Does it crash or is it slow? Do you have enough RAM to keep all the extra items?

rk123
31st March 2010, 21:12
It is slow. I have plenty of RAM. Running ./chip takes about 1.9G with my hack. I have 8G RAM on my machine and it is available.

wysota
31st March 2010, 23:32
It is slow.
So what's the backtrace for?

Anyway, you can make things faster if you disable indexing in the scene. Even in the backtrace you can see there is BSP algorithm involved there. On the other hand bsp indexing shouldn't happen when you set the scene on a view but rather when you add items to the scene...unless GV delays building the index until you access some method that might actually need it. Is there something specific you are doing before calling setScene()?

rk123
1st April 2010, 18:22
Yes, I see the BSP algorithm kick in. I am not sure why. This is coming from QT:
qt-everywhere-opensource-src-4.6.1/demos/chip
If you put in the patch I had mentioned, you will see that too.
Hence, my question of if I am doing something wrong or is it a QT bug.