Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Save the Climate with Xcode

Save the Climate 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

February 27, 2019
Tweet

More Decks by Manu Carrasco Molina

Other Decks in Programming

Transcript

  1. Save the climate with Xcode If one developer can change

    a room... Manuel @stuffmc Carrasco Molina @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 1
  2. Small things adds up. Consume less. —Each one of us

    can spare on its own gear —LG Ultrafine 5K: Up to 2kWh/day. 211 €/Year.1 —iMac Pro: Up to 370 W... Worst. —How can we have an impact on lots of people? —Apps! Yes we can (optimize) 1 https://www.lg.com/us/business/commercial-display/it-products/desktop-monitors/lg-27MD5KB-B 10 h * 200 W * 365 * 0.29 cts. Devs in this room responsible for being able to turn down a power plant? @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 2
  3. One line can change the code2 —And if can change

    the code, it can change the app —And if can change the App, then the world 2 https://youtube.com/watch?v=AmUUYo9o9eg @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 3
  4. 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 climate with Xcode, Feb '19, Cocoaheads 5
  5. 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 climate with Xcode, Feb '19, Cocoaheads 6
  6. Activity of your app —Always an overhead (of the OS

    also) —Peaks in Energy usage when your app is used @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 9
  7. An app lifetimes —Sometimes resting —Sometimes doing more —Just like

    your iMac consuming more energy @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 10
  8. In General —Coalesce! Batch! —Think about the cost of starting

    the radios @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 13
  9. Processing —Avoid NSTimer. If at all, Coalesce with leeway —e.g.

    News App? Let the user refresh! @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 14
  10. Networking —Use earliestBeginDate3 from NSURLSessionTask —Balance between huge calls and

    many tiny calls —More network requests = more energy 3 earliestBeginDate Start the network load for this task no earlier than the specified date. @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 15
  11. Sending analytics —The best way to do it? Don't send

    analytics. —If you really can't quit the job where your company forces to do so... —Send them in batches: discretionary from NSURLSessionConfiguration 4 4 discretionary: Allows background tasks to be scheduled at the discretion of the system for optimal performance. @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 16
  12. Location —start/stopLocation? requestLocation5! —Region Monitoring instead of checking location! —Lower

    the desired location accuracy6 —Don't forget to stop (when you get enough)! 6 e.g. to 3 KM if you can. 5 requestLocation: Request a single location update. @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 18
  13. Graphics —Minimize screen updates —Review blur usage —Do you really

    need that animation? —OpenGL? Make your app mux-aware @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 20
  14. Video Player —Optimized from Apple —Don't show persistent UI Controls

    too long @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 21
  15. Energy Gauges ⚠ Not working on Simulator @stuffmc • Save

    the climate with Xcode, Feb '19, Cocoaheads 23
  16. Instruments —Untethered Profiling! —Maybe environmental problems —Many Profiling Templates —Many

    Talks @ Conferences @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 29
  17. 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 climate with Xcode, Feb '19, Cocoaheads 30
  18. References —WWDC 17: Writing Energy Efficient Apps —WWDC 18: What’s

    New in Energy Debugging —Work/Talk in Progress... —Questions? @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 33