Upgrade to Pro — share decks privately, control downloads, hide ads and more …

XebiCon | iOS: Full Speed Ahead in your Pants (...

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.

More Decks by Jeroen Leenarts (AppForce1)

Other Decks in Programming

Transcript

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

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

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

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

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

    Xebia internal review only. PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL 9
  6. 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"
  7. 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
  8. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. WHY DOES IT MATTER? 12
  9. 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
  10. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. ALWAYS A TRADE-OFF 16
  11. 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
  12. 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
  13. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

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

    Xebia internal review only. IT’S ALL ABOUT THE TOOLS 20
  15. 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
  16. 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
  17. Copyright © 2014 Xebia Netherlands B.V. All rights reserved. For

    Xebia internal review only. GO FORTH AND OPTIMIZE 25
  18. 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
  19. 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
  20. 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
  21. 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