Discussion - Energy Efficiency for iOS Apps\n\n\nApple\u2019s Energy Efficiency Guide\n\n\n\nAre you telling me I have to worry about my app\u2019s power consumption?\n\n\nThis is iOS. I thought Apple was taking care of that for me...right??\n\n\n\nWhat is Energy?\n\n\nPower is an instantaneous measurement of energy at any given point in time\nEnergy is power used over time (Joules measured over watt-hours)\nLow power used over a long(er) period of time can amount to the same energy expenditure as short bursts of high power (more on this later)\n\n\n\nMajor sources of energy consumption/power draw\n\n\nDevice wake\n\n\nAside from being powered off, a device in its sleep state is consuming the lowest amount of energy possible\nWhenever possible, avoid preventing the device from sleeping or forcing it to awaken\nUse technologies like push and background tasks judiciously\n\n\nCPU Usage\n\n\nAn idle CPU uses ~10x the power of a sleeping CPU\nJust 1% CPU use costs 10% more than idle\n10% CPU use costs 200% that of an idle CPU\n100% CPU can result in 1000% (10x) power draw compared to idle\n\n\nNetworking / Bluetooth\nGraphics/animation/video\nSensors\n\n\nLocation (Wi-Fi/GPS)\nAccelerometer\nGyroscope\nMagnetometer\n\n\nDisk IO. Use batch operation whenever possible\n\n\n\nMitigating energy costs\n\n\nBatching, Batching, Batching\n\n\nOperations have a dynamic and fixed energy cost\n\n\nFixed cost represents the energy used while the device is waiting to enter an idle state\nThe same amount of work, performed across multiple threads, can have a significantly lower total energy cost compared against single-threaded work requiring a longer time to execute\n\n\nNetwork and other inter-device (BT, for example) operations require radios to be powered up. Avoid continuous communications and state polling, batching operations whenever possible\nDefer any operations that aren\u2019t time-sensitive to time that the app will be otherwise active (take advantage of fixed cost you\u2019re already having to pay)\n\n\nPrioritize operations using Quality of Service Classes (iOS 8+)\n\n\nClasses\n\n\nUser-interactive\nUser-initiated\nUtility\nBackground\n\n\nCan be set on both NSOperationQueue and individual NSOperation objects\nGCD queues can be created with QOS class attributes\n\n\nUse timers efficiently, or better yet, avoid them\n\n\nGCD provides mechanisms you can use instead of timers, for example dispatch_block_wait()\nIf you must use timers (not just NSTimer: basically anything that takes a time interval as a deadline), take advantage of APIs that allow for timer coalescing using tolerances.\n\n\nMinimize I/O\nReact to Low Power Mode (iOS 9)\n\n\nNSProcessInfoPowerStateDidChangeNotification\n[[NSProcessInfo processInfo] isLowPowerModeEnabled]\n\n\n\n\n\nInstruments to the Rescue\n\n\nEnergy Diagnostics Logging\n\n\n\nOther Resources\n\n\nPerformance Tips from Apple\n\n\n\nPicks\n\nJohn\n\n\n\u2018Operator\u2019 font created by Hoefler & Co., a font design company\n\n\n\nDarryl\n\n\nAchieving All-day Battery Life\n\n\n\nAlternative show title suggestions\n\n\nPower Draw\nContribute to Sleep\nDon\u2019t write an app\n(You should) Get off of the main thread\nThey DID bone it\nI ripped them off