smashing the bottleneck: qt application profiling

16
Agenda Why Prformanc Mattrs How You Can Improv Prformanc 3

Upload: develer-srl

Post on 29-Nov-2014

2.026 views

Category:

Technology


1 download

DESCRIPTION

Smashing the bottleneck: Qt application profiling

TRANSCRIPT

Page 1: Smashing the bottleneck: Qt application profiling

Agenda

• Why Performance Matters

• How You Can Improve Performance

3

Page 2: Smashing the bottleneck: Qt application profiling

Why Performance Matters

• Attractive to users

• Looks more professional

• Help you get things done more efficiently

• Keeps the flow

4

Page 3: Smashing the bottleneck: Qt application profiling

Why Performance Matters

• An example explains more than a thousand words

5

Page 4: Smashing the bottleneck: Qt application profiling

Why Performance Matters

• Performance is more important than ever before– Dynamic user interfaces

• Qt Everywhere– Desktop– Embedded platforms with limited hardware

• We cannot just buy better hardware anymore

• Clock speed vs. number of cores

6

Page 5: Smashing the bottleneck: Qt application profiling

Why Performance Matters

• Not all applications can take advantage of

multiple cores

• And some will actually run slower:

– Each core in the processor is slower

– Most applications not programmed to be multi-

threaded

• Multi-core crisis?

7

Page 6: Smashing the bottleneck: Qt application profiling

Agenda

• Why Performance Matters

• How You Can Improve Performance

19

Page 7: Smashing the bottleneck: Qt application profiling

How You Can Improve Performance

• Theory of Constraints (TOC) by Eliyahu M. Goldratt• The theory is based on the idea that in any complex

system, there is usually one aspect of that system that limits its ability to achieve its goal or optimal functioning. To achieve any significant improvement of the system, the constraint must be identified and resolved.

• Applications will perform as fast as their bottlenecks

20

Page 8: Smashing the bottleneck: Qt application profiling

Theory of Constraints

• Define a goal:– For example: This application must run at 30 FPS

• Then:1) Identify the constraint 2) Decide how to exploit the constraint3) Improve4) If goal not reached, go back to 1)5) Done

21

Page 9: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• The number one and most important task

• Make sure you have plausible data

• Don't randomly start looking for slow code paths!– An O(n2) algorithm isn't necessarily bad– Don't spend time on making it O(n log n) just for fun

• Don't spend time on optimizing bubble sort

22

Page 10: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• “Bottlenecks occur in

surprising places, so

don't try second guess

and put in a speed hack

until you have proven

that is where the

bottleneck is” -- Rob Pike

23

Page 11: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• The right approach for identifying hot spots:

– Any profiler suitable for your platform• Shark (Mac OSX)• Valgrind (X11)• Visual Studio Profiler (Windows)• Embedded Trace Macrocell (ETM) (ARM devices)

• NB! Always profile in release mode

24

Page 12: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• Run application: “valgrind --tool=callgrind ./application”

• This will collect data and information about the program

• Data saved to file: callgrind.out.<pid>

• Beware:– I/O costs won't show up– Cache misses (--simulate-cache=yes)

• The next step is to analyze the data/profile• Example

25

Page 13: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• Profiling a section of code (run with “–instr-atstart=no”):

26

#include<BbrValgrind/callgrind.h>

int myFunction() const{ CALLGRIND_START_INSTRUMENTATION; int number = 10; ... CALLGRIND_STOP_INSTRUMENTATION; CALLGRIND_DUMP_STATS;

return number;}

Page 14: Smashing the bottleneck: Qt application profiling

Identifying hot spots (1)

• When a hot-spot is identified:– Look at the code and ask yourself: Is this the right

algorithm for this task?

• Once the best algorithm is selected, you can exploit the

constraint

27

Page 15: Smashing the bottleneck: Qt application profiling

How to exploit the constraint (2)

• Optimize– Design level– Source code level– Compile level

• Optimization trade-offs:– Memory consumption, cache misses– Code clarity and conciseness

28

Page 16: Smashing the bottleneck: Qt application profiling

Theory of Constraints

• Define a goal:– For example: This application must run at 30 FPS

• Then:1) Identify the constraint 2) Decide how to exploit the constraint3) Improve4) If goal not reached, go back to 1)5) Done

65