[Development] Item creation time in QML

Robin Burchell robin+qt at viroteck.net
Wed Feb 18 10:33:36 CET 2015


On Fri, Feb 13, 2015 at 12:41 AM, Andrew den Exter
<andrew.den.exter at qinetic.com.au> wrote:
> First of all it's accumulative, any QML application is going to end up
> constructing many items, hundreds, thousands even and costs, even small ones
> add up.  Secondly yes constructing and interacting with QObjects can be
> expensive and there are ways to mitigate some of those costs.   Thirdly
> parsing, compiling, instantiating, and executing bindings is all extra work
> that comes at a cost.

I would also add that memory allocation is usually a problematic
thing. This can be something as "simple" as using the wrong type of
container as was discussed on the list recently. See
ba690fb73864915b4a35bbec5b7dc134ff1dafd0 in qtdeclarative for one
recent example of just how bad this can get.

> Robin's singled out the Text items so lets have a look at those.  A good
> amount of work has already been put into these items though so TextEdit
> aside there's not a lot of low hanging fruit.

Looking into a time profile on Gunnar's Text benchmark a little,
here's some intriguing findings so far:

* I started out with a split of 33% - 66% render thread vs gui thread
split. This is quite high, the render thread is normally a lot less
busy.
* Profiling showed a lot of "hot path" memory allocation on various
small spots, e.g.
  https://codereview.qt-project.org/#/c/106259/
  https://codereview.qt-project.org/#/c/106260/
  https://codereview.qt-project.org/#/c/106261/
  https://codereview.qt-project.org/#/c/106262/
* Profiling also shows that (once again) QHash and QSet are looking
likely to be problematic in a few places. I've already gotten rid of a
few of them in a WIP patch I haven't pushed yet.

On the GUI thread:
* 11% in QQmlObjectCreator::create
    * 1% in QQuickText::QQuickText
    * 6.5% in QQmlObjectCreator::setupBindings
* 52% in QQmlObjectCreator::finalize
    * 47% on QQuickText::componentComplete
        * 35% in QTextLine::layout_helper
            * 30% in QTextEngine::shapeText
                * 28% in QTextEngine::shapeTextWithHarfbuzzNG
                    * 26% in hb_shape_full
    * 5% in QQmlBinding::update

On the render thread:
* 15% in QSGRenderThread::sync
    * 14% in QQuickWindowPrivate::updateDirtyNodes
        * 8.5% in QQuickWindowPrivate::updateDirtyNode
            * 7% in QQuickText::updatePaintNode
                * 4% in QQuickTextNodeEngine::addToSceneGraph
                * 1% in QSGNode::appendChildNode
                    * 1% in QSGBatchRenderer::Renderer::nodeChanged
        * 5.2% in ~QSGTransformNode
            * 3.6% in ~QQuickTextNode
            * 1.5% in QSGNode::removeChildNode
                * 1.5% in QSGBatchRenderer::Renderer::nodeChanged
* 3.7% in QQuickWindowPrivate::renderSceneGraph

So we have total costs of around 35% for text engine costs, 11.5% for
binding costs, and the actual Text construction isn't much to speak
about.



More information about the Development mailing list