Smashing the bottleneck: Qt application profiling

2,408 views
2,209 views

Published on

Smashing the bottleneck: Qt application profiling

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,408
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Smashing the bottleneck: Qt application profiling

  1. 1. Agenda• Why Performance Matters• How You Can Improve Performance 3
  2. 2. Why Performance Matters• Attractive to users• Looks more professional• Help you get things done more efficiently• Keeps the flow 4
  3. 3. Why Performance Matters• An example explains more than a thousand words 5
  4. 4. 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
  5. 5. 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
  6. 6. Agenda• Why Performance Matters• How You Can Improve Performance 19
  7. 7. 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
  8. 8. 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 constraint 3) Improve 4) If goal not reached, go back to 1) 5) Done 21
  9. 9. Identifying hot spots (1)• The number one and most important task• Make sure you have plausible data• Dont randomly start looking for slow code paths! – An O(n2) algorithm isnt necessarily bad – Dont spend time on making it O(n log n) just for fun• Dont spend time on optimizing bubble sort 22
  10. 10. Identifying hot spots (1) • “Bottlenecks occur in surprising places, so dont try second guess and put in a speed hack until you have proven that is where the bottleneck is” -- Rob Pike 23
  11. 11. 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
  12. 12. 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 wont show up – Cache misses (--simulate-cache=yes)• The next step is to analyze the data/profile• Example 25
  13. 13. Identifying hot spots (1)• Profiling a section of code (run with “–instr-atstart=no”): #include<BbrValgrind/callgrind.h> int myFunction() const { CALLGRIND_START_INSTRUMENTATION; int number = 10; ... CALLGRIND_STOP_INSTRUMENTATION; CALLGRIND_DUMP_STATS; return number; } 26
  14. 14. 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
  15. 15. 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
  16. 16. 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 constraint 3) Improve 4) If goal not reached, go back to 1) 5) Done 65

×