Slide 1

Slide 1 text

PERFORMANCE TUNING ON IOS Jeroen Leenarts! Rotterdam, June 2014! [email protected] 10 April 2014 1

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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"

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Cause under 60 fps
 simply won’t do… You only got 1/60th of second

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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