views:

175

answers:

1

I'm using the Qt graphics API to display layers in some GIS software.

Each layer is a group, containing graphic primitives. I have a performance issue when loading fairly large data sets, for example this is what happens when making a group composed of ~96k circular paths (points from a shapefile):

callgrind image

The complete callgrind dump is here.

The QGraphicsScene::createItemGroup() call takes about 150 seconds to complete on my 2.4GHz core2, and it seems all this time is used in QGraphicsItemPrivate::updateEffectiveOpacity(), which itself consumes 37% of its time calling QGraphicsItem::flags() 4 billion times (the data comes from a test script with no GUI, just a scene, not even tied to a view).

All the rest is pretty much instantaneous (creating the items, reading the file, etc...). I tried to disable the scene's index before creating the group and obtained similar results.

What could I do to improve performances in this case ? If I can't is there a way to create groups faster ?

+2  A: 

After studying the source code a little bit, I found out that the updateEffectiveOpacity has O(n²) with regard to the children of the item's parent item (search for the method qt_allChildrenCombineOpacity). This is probably also the reason that method disappeared in Qt 4.6 and apparently been replaced by something else. Anyway, you should try out setting the ItemDoesntPropagateOpacityToChildren flag on the group item (i.e. you'll have to create it yourself), at least while adding all the items.

Torsten Marek
Yes ! my loading time went down to a few seconds, which is still slow but sure more acceptable than over 2 minutes :) (I still reactivate the flag once the group is created). Thank you very much !
Luper Rouch