Home · All Classes · All Functions · Overviews

Optimizing Performance in QML

The Qt Declarative module includes several tools to help measure performance.

Performance Logging

The declarative module uses the functionality provided by QPerformanceLog to log performance information. To see this information you can add the following to src.pro:

 DEFINES += Q_ENABLE_PERFORMANCE_LOG

The performance information will be printed to screen on a QML application startup, or when running the viewer can be forced at anytime by pressing 'F3' on the keyboard.

Additional logging can be enabled by adding the relevant categories to qfxperf.h and qfxperf.cpp.

For example, to measure the cost of calculating the size of a text item, you would first define a TextSize category by adding the following:

 //in qfxperf.h
 Q_DECLARE_PERFORMANCE_METRIC(TextSize);

 //in qfxperf.cpp
 Q_DEFINE_PERFORMANCE_METRIC(TextSize, "Text Size Calculation");

You could then use this category in the code:

 void QDeclarativeText::updateSize()
 {
     QDeclarativePerfTimer<QDeclarativePerf::TextSize> perf;
     ...
 }

Because there is no cost for a QDeclarativePerfTimer when Q_ENABLE_PERFORMANCE_LOG is not defined, this line can persist in the code and be used to help detect performance bottlenecks and regressions. See the QPerformanceLog documentation for more information on this performance framework.

FPS Measurements

When running the viewer, pressing 'F2' on the keyboard while a QML program is running will cause information on cost-per-frame and frames-per-second (FPS) to be printed to the console.

The information printed includes:

Improving Performance

The following tips can help decrease startup time for QML-based appications.

Images

Fonts


Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0