Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 4

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 7

Slide 8

Slide 8 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 8

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 11

Slide 12

Slide 12 text

The 4 !fantastics @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 12

Slide 13

Slide 13 text

In General —Coalesce! Batch! —Think about the cost of starting the radios @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 13

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Video Player —Optimized from Apple —Don't show persistent UI Controls too long @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 21

Slide 22

Slide 22 text

The Tools @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 22

Slide 23

Slide 23 text

Energy Gauges ⚠ Not working on Simulator @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 23

Slide 24

Slide 24 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 24

Slide 25

Slide 25 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 25

Slide 26

Slide 26 text

Foreground/Background/Suspended @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 26

Slide 27

Slide 27 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 27

Slide 28

Slide 28 text

@stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 28

Slide 29

Slide 29 text

Instruments —Untethered Profiling! —Maybe environmental problems —Many Profiling Templates —Many Talks @ Conferences @stuffmc • Save the climate with Xcode, Feb '19, Cocoaheads 29

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

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