Top Banner
Performance Tips & Tricks for Qt-QML Apps Rajesh Lal, Nokia
32

Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

May 19, 2015

Download

Technology

Raj Lal

Learn the Best practices for QML Application Architecture, Know the Tips and tricks related to show QML in a MeeGo device. Best practices for Qt/QML development and conventions to avoid in QML development. Learn the programming guidelines that apply to QML.

A refreshing list of Tips and Tricks and to optimize your QML applications and know what to avoid.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

Performance Tips & Tricks for Qt-QML Apps Rajesh Lal, Nokia

Page 2: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

2

Qt UI Creation Kit

Qt Quick Most Advanced UI

QML

+ =

High Performance

MeeGo Apps

High Performance QML Applications

Page 3: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

3

Agenda

Qt Quick QML App

7 Tips Tools

Page 4: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

4

The Fastest way to develop for MeeGo

What is Qt Quick

• QML • IDE – Qt Creator • Qt UI Designer • Plugin for Mobility API • Quick Components

Page 5: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

5

The Most Advanced UI technology for Mobile

What is QML

• Qt Meta-Object Language • JavaScript based • Qt Declarative runtime • CSS-JavaScript like syntax

Page 6: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

6

QML

Powerful Declarative

User Interface language

Page 7: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

7

Graphics

Items

Shapes

Text

Animation

State

Transitions

Transform.

Binding

Property

JavaScript

C++

QML Elements

Page 8: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

8

What is a Qt QML App

A Qt Container (main.cpp)

UI in QML (main.qml)

Logic in JavaScript or C++ API calls

Qt Quick Application

Page 9: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

9

QML App. Viewer

UI

1 | 2 | 3

Qt-QML App

Logic Property Bind JavaScript C++ Binding

1+ QML Files Import libraries

Import JS files

Qt Container(main.cpp)

Page 10: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

10

What is Performance

• Short response time • High Throughput • Low utilization of resources • High availability • High Speed • Instant • Smoothness

Page 11: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

11

7 Tips for High Performance QML Application

Page 12: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

12

Tip 1 Divide and Rule

Page 13: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

13

1: Divide and Rule

• Divide application UI into multiple QML files • Each Logical entity as a separate QML file • Think Object Oriented Programming • Do not use 1 Large QML file

Page 14: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

14

1: Divide and Rule

Rule • Use main.qml as the main UI

₋ With different States & Transitions ₋ Create Multiple Views .QML files ₋ Import folders containing other QML files ₋ Local instances of imported QML elements

Page 15: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

15

1: Divide and Rule

Page 16: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

16

Tip 2 Load and Unload

Page 17: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

17

2: Load and Unload

• Use Loader to control the memory usage • Load the absolute Minimum at the startup • Dynamically Load and Unload UI Components • Create Components when required

Page 18: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

18

2: Load and Unload

Page 19: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

19

Tip 3 Use Asynchronous Threads

Page 20: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

20

3: Asynchronous Threads

• Use WorkerScripts for Remote API Calls • Use Threads for time consuming operations • Load large images asynchronously • Use caching for remote data/image

(cacheBuffer in listview/Gridview)

Page 21: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

21

3: Asynchronous Threads

Login call in MyApp.QML MyAppScript/Login.QML file

Page 22: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

22

3: Asynchronous Threads

Js/dologin.js

Page 23: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

23

Tip 4 Optimize for Images

(Greatest User of Memory)

Page 24: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

24

4: Optimize for Images

• Optimize Images to reduce memory footprints • Specify exact size of the image • Avoid resizing/scaling an image in QML • Lazy load large images (asynchronous=true) • Don’t cache large images (cache=false) • Smooth filter = better visual quality, but slower

Page 25: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

25

Tip 5 Beware of String Operations

Page 26: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

26

5: Beware of String Operations

• Strings are immutable • multiple '+' operator = multiple memory allocations • Use StringBuilder for more efficient strings • Define

₋ #define QT_USE_FAST_CONCATENATION ₋ #define QT_USE_FAST_OPERATOR_PLUS

Page 27: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

27

Tip 6 Know States, Transitions, & Animations

Page 28: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

28

6: Know States, Transitions, & Animations

• In transition, animated area should be small • Animate different items sequentially when possible • Avoid multiple timers during animation • Avoid JavaScript operations during animation • Use ScriptAction & StateChangeScript

Page 29: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

29

Tip 7 Follow Best Practices

Page 30: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

30

7: Best Practices

• For best performance use C++ instead of JavaScript • Insert properties at top of element declarations • Create application logic outside QML • Don’t build multiple layer of QML hierarchies • Use Qt's i18n for internationalisation & localisation

Page 31: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

31

Tools

QML Performance Monitor http://www.youtube.com/watch?v=XdI9C53uJw8 Valgrind http://valgrind.org/docs/manual/mc-manual.html QML Performance Guidelines http://doc.qt.nokia.com/4.7/qdeclarativeperformance.html

Page 32: Performance Tips & Tricks for QT/QML Apps: MeeGo Conference San Francisco, Hyatt Regency, May 23-25,2011 @iRajLal

Thank You @rajeshlalnokia