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

Save the Environment with Xcode

Save the Environment with Xcode

As developers we are highly environmentally responsible for our code. It's how we start and stop location or other hardware that decides how fast the battery will be empty, thus on much batteries a user will need in its lifetime, and how much electricity (in various ways) have to be produced. Although it's sadly something Apple doesn't check, I'll give you a few hint at what you should do and shouldn't do to be greener developer.

Manu Carrasco Molina

June 03, 2019
Tweet

More Decks by Manu Carrasco Molina

Other Decks in Programming

Transcript

  1. Save the environment with Xcode One line can change a

    code... Manuel @stuffmc Carrasco Molina Code 4 Future @stuffmc • Save the environment with Xcode, June '19, AltConf Paris
  2. > whoami && whyami? ✔ ! guy born in "

    living in since 16 years → ✔ 22 years of software dev, 11 with techs → ✔ 8 years of political involvement with the party ✔ 5 years of climate ) & refugees activism ✔ 6 + years , without - meat, half of it vegan @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 3
  3. Ethics FTW This talk is about your Karma... @stuffmc •

    Save the environment with Xcode, June '19, AltConf Paris ! 4
  4. 5

  5. One line can change the code ✔ If can change

    the code, it can change the App ✔ If can change the App, it can change the Phone ✔ With over 2.2 billion Phones... ✔ It can change the World! @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 6
  6. Your Code can change the world ✔ Don't let energy

    optimization be the next testing ✔ There's never enough time or money for testing ✔ Same with Security... ✔ Some Security Company have no time for design @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 7
  7. Settings > Battery ✔ Where the user will go if

    the battery is draining. ✔ You don't want your app in this list. ✔ It's like the losers list. @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 8
  8. 9

  9. 10

  10. Four by Four ✔ Identify the problem that is causing

    the drain ✔ Optimize the code for less battery usage ✔ Reduce the amount of things your code do ✔ Coalesce tasks that can be grouped together @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 15
  11. [Background] Processing ✔ Avoid NSTimer (User refresh, notification, ...) ✔

    Call Completion Handler! @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 16
  12. Networking ✔ Use NSURLSessionTask's earliestBeginDate ✔ Balance between huge calls

    and many tiny calls ✔ More network requests = more energy ✔ Session Config: waitsForConnectivity @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 19
  13. Sending analytics ✔ The best way to do it? Don't

    send analytics. ✔ Your company forces to do so? Can't quit? ✔ Send them in batches ✔ Session Config: discretionary @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 20
  14. Location ✔ start/stopLocation? requestLocation! ✔ Region Monitoring instead of checking

    location! ✔ Lower location accuracy (to 3 KM if you can) ✔ Don't forget to stop (when you get enough)! @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 21
  15. Graphics ✔ Minimize screen updates ✔ Review blur usage ✔

    Do you really need that animation? ✔ OpenGL? Make your app mux-aware @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 22
  16. Video Player ✔ Optimized from Apple ✔ Don't show persistent

    UI Controls too long ✔ Tagesschau layers controls on top @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 23
  17. Energy Gauges Not working on Simulator @stuffmc • Save the

    environment with Xcode, June '19, AltConf Paris 25
  18. Instruments ✔ Untethered Profiling! ✔ Maybe environmental problems ✔ Many

    Profiling Templates ✔ Many Talks @ Conferences @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 30
  19. Energy Logs & Organizer ✔ Similar to crash logs ✔

    Agregated Logs from your users ✔ 2 weeks of History ✔ Data from TestFlight and App Store @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 31
  20. References ✔ WWDC 17: Writing Energy Efficient Apps ✔ WWDC

    18: What’s New in Energy Debugging ✔ Energy Efficiency Guide for iOS Apps @stuffmc • Save the environment with Xcode, June '19, AltConf Paris ! 33