XebiCon | iOS: Full Speed Ahead in your Pants (Performance tuning on iOS)

XebiCon | iOS: Full Speed Ahead in your Pants (Performance tuning on iOS)

Mobile phones are becoming more and more powerful. The amount of computing power people carry in their pockets nowadays is mind boggling. But still, mobile devices are very much constrained by their battery capacity. So it is important to be frugal about processor cycles, network calls, GPS and other power sinks. It is also important to achieve 60 frames per second, even if you are just creating yet another weather app.
In this session Jeroen will show how you can analyse and improve processor usage on your iOS app. The principals are general and applicable to any other platform, but Jeroen will explain these principles with Xcode and iOS.

8ae8744c09ee9e24e9de32d406c9ed9f?s=128

Jeroen Leenarts

June 05, 2014
Tweet

Transcript

  1. PERFORMANCE TUNING ON IOS Jeroen Leenarts! Rotterdam, June 2014! jleenarts@xebia.com

    10 April 2014 1
  2. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL 2
  3. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. JEROEN LEENARTS iOS Developer! 10+ years! 3
  4. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 4
  5. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 5
  6. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 6
  7. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL 7
  8. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. …ABOUT THAT QUOTE… 8
  9. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL 9
  10. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 10 "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. ! Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified"
  11. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. IOS PERFORMANCE TUNING ! Why does it matter?! ! What uses energy?! ! It’s all about the tools! ! Obvious things to do? 11
  12. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. WHY DOES IT MATTER? 12
  13. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 13
  14. Cause under 60 fps
 simply won’t do… You only got

    1/60th of second
  15. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. WHAT USES ENERGY 15 What Uses Energy? I/O CPU Graphics
  16. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. ALWAYS A TRADE-OFF 16
  17. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. ALWAYS A TRADE-OFF Using CPU is usually better compared to network I/O! Using memory is usually better compared to CPU 17
  18. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. APPLE SAYS Be absolutely idle when app is not in use! Eliminate nonuser-driven work! Wait quietly for user input! ! Be efficient when user requests action! Performance = power! Efficient, multithreaded algorithms win (use GCD)! Then race back to idle 18
  19. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. RACE BACK TO IDLE 19
  20. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. IT’S ALL ABOUT THE TOOLS 20
  21. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. I’LL SHOW Some Xcode! ! Some Instruments! ! Some iOS Simulator 21
  22. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 22
  23. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. 23
  24. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. OBVIOUS THINGS TO DO Use ARC! Use a reuseidentifier! Don’t be transparant! Don’t block the main thread! Size image resources appropriately! Enable GZip compression! Set the shadow path 24
  25. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. GO FORTH AND OPTIMIZE 25
  26. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. OBVIOUS THINGS TO DO? Reuse and lazy load when appropriate! Cache! Re-use expensive objects (DateFormatters!!)! Let someone/something else do the work. 26
  27. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. TABLE VIEW TIPS You should reuse cells with the correct reuseIdentifier.! As many views as possible should have the opaque setting, including the cell itself.! Avoid sequences, scaled images and offscreen drawing.! If the height of the lines varies, they should be cached.! 27
  28. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. TABLE VIEW TIPS If a cell shows contents from the web, queries should take place asynchronously and the responses should be cached.! Shadows can be created with shadowPath.! The number of subviews should be kept low. 28
  29. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. LINKS ! https://github.com/jeroenleenarts/FibonacciTest! https://github.com/jeroenleenarts/PerformanceFunHouse! http://www.raywenderlich.com/31166/25-ios-app-performance-tips- tricks! WWDC 2012 session 712
 https://developer.apple.com/videos/wwdc/2012/! https://developer.apple.com/library/mac/documentation/ DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/ Introduction.html! https://developer.apple.com/library/ios/documentation/iphone/ conceptual/iphoneosprogrammingguide/PerformanceTuning/ PerformanceTuning.html 29