How OS X “Mavericks” works its power-saving magic

More details on App Nap, Timer Coalescing, and Compressed Memory.

At yesterday's Worldwide Developer Conference (WWDC) keynote, Apple made some bold claims about the future of battery life in its laptops. A new 13-inch Macbook Air, for instance, should now run a full 12 hours on a single charge, up from 7 in the previous model. Assuming that testing bears out Apple's numbers, how did the company do it? The obvious part of the answer is "Haswell"—but that turns out to be only part of the story.

The power efficiency gains found in Intel's new Haswell CPUs should provide modest gains in battery life, and such gains were widely expected. Back in January, Intel claimed that the new Haswell CPUs featured the "largest generation-to-generation battery life increase in the history of Intel" and said that the chips were the first of its architectures designed "from the ground up" for Ultrabooks and tablets. The new chips run at lower clockspeeds and at lower wattages.

Less expected was the announcement of OS X 10.9 "Mavericks" and its own focus on mobile power usage. While Apple made a few comments during the keynote about the new technologies meant to enable longer battery life, more information appeared later in the day with the separate release of a Core Technology Overview (PDF) document that offers a high-level look at some of the Mavericks internals.

The overarching goal of the power efficiency changes is of course longer battery life, but Apple claims that it can acheive this without harming "and in some cases even improving" overall system responsiveness. Three main technologies make this possible.

First up: compressed memory. Not ordinarily thought of as a power management tool, compressed memory "automatically compresses the least recently used items in memory, compacting them to about half their original size." When the items are needed, they are uncompressed and presented to the requesting program.

Apple claims that this compression/decompression cycle within memory is faster than swapping the information out to disk, even when that disk is an SSD, thanks to its use of the old WKdm algorithm. (And running Mavericks on older laptops with mechanical disks should result in even more dramatic savings.) A 2003 academic paper (PDF) comparing the speed of three "live RAM" compression algorithms concurs, concluding, "WKdm compresses and decompresses extremely fast, outperforming the other two [tested] algorithms in both respects." This frees overall memory, increases speed (compared with swapping to disk), and lowers disk wear, but Apple claims that it also "reduces the need to read and write virtual memory swap files on disk, improving the power efficiency of your Mac," despite the small increase in CPU usage due to the compression and decompression.

The second technology is App Nap. The new feature clamps down harder on apps that aren't in the foreground. (One of our Mac-using editors notes that the current version of Safari consumes about 15 percent of CPU resources when running in the background, so these power losses can be significant.) The default scenario is to aggressively throttle resources when "an app's windows are not visible and the app is not playing audio" (though devs can override this behavior). When an app is "napping," OS X throttles its program timers, limiting their frequency to generate "significant improvements in CPU idle time when running applications that frequently check for data."

Disk and network activity are both more limited than before, too. A napping app receives the "lowest priority" for disk and network access, which is meant to reduce disk power usage but also to make foreground apps more responsive. "I/O throttling reduces the chance that a background process will interfere with the I/O activity of an app that you are actively using," says Apple.

Mavericks will also lower the UNIX process priority of any napping app so that it receives a smaller slice of CPU resources. Together, the changes should exert more control over background apps and keep their power consumption in check—though with opt-out controls for any apps designed to run at full power in the background.

Finally, Apple introduces something called Timer Coalescing, which only operates while a machine is on battery power. OS X programs are constantly setting timers that can activate the CPU, the disk, or the network link to do everything from checking DHCP WiFi leases to running Software Update to triggering an audible alarm. (Most of these timers result in action that is invisible to the user.) Because apps don't coordinate their timers at all, an idling Mac can be constantly awakened by firing timers, keeping CPUs and disks out of their lowest-power idle states.

Non-coalesced timers. Note the power use line across the bottom.

Apple

Timer Coalescing attempts to enforce some order on all this chaos. While on battery power, Mavericks will routinely scan all upcoming timers that apps have set and then apply a gentle nudge to line up any timers that will fire close to each other in time. This "coalescing" behavior means that the disk and CPU can awaken, perform timer-related tasks for multiple apps at once, and then return to sleep or idle for a longer period of time before the next round of timers fire.

Apple has never guaranteed developers that timers will run at exact times, either, so this isn't necessarily a break with convention. Apple currently tells developers that "because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds," and it notes that busy apps may have their timers affected even more. Current apps that set a 0.1s timer, for instance, only get something within +/- 0.00001s or so, and Apple sounds like it will get even more "approximate" with timer scheduling in Mavericks.

Apple claims the technique can "dramatically increase the amount of time that the processor spends idling," and it uses this illustrative chart to show the possible improvement in power usage:

After Timer Coalescing applied. Power usage line shows more overall idle time.

Apple

The new technologies exist alongside some kernel-level adjustments to the way CPU resources are used—Mavericks prefers to use as few cores as possible, leaving others totally idle so long as demand allows it. Paired with the Haswell improvements, Apple is making some dramatic claims for battery life improvements—and we'll be putting them all to the test.

Sounds like this is just back-porting all of the stuff learned about power management for mobile to the desktop. I do wonder how many programs will have problems with it though, messing with timers is likely to lead to subtle bugs.

I'm glad this update is focusing on such optimisations. At this point, the two main priorities for OSes are security and power consumption, IMHO. Mavericks is just a terrible name though, Apple really missed an opportunity by not going with Sea Lion: the latter would have suggested lateral thinking, lightheartedness, and a sense of humour. Mavericks sounds like something Intel or Microsoft would have come up with; with all due respect to those two very impressive companies, it's fair to say that they have cultivated a different, more sober business-oriented public image.

Mavericks prefers to use as few cores as possible, leaving others totally idle so long as demand allows it.

Doesn't this go against Intel's own philosophy of clocking everything up to 11 to finish the task as fast as humanly possible so the cores can go back to idle? This seems like what Qualcomm and nVidia tend to do on the ARM side of things instead of what Intel does.

It's not, as far as I can see, a bullet point feature that a customer would see, or give a crap about. This is a feature of the OS that developers HAVE to know about. It doesn't matter if Windows has had it for 1 or 20 years, as that's completely irrelevant.

All of these items together will be a marketing bullet point of "Better battery Life", but that, you would have to agree, is more than fair.

The real question is how much is this going to affect non-Haswell MacBooks. Since those items don't sound particularly Haswell centric (other than the last one possibly, although that too should be possible on other platforms like Sandy Bridge and Ivy Bridge, albeit with less ROI because of the lesser capabilities of those CPUs in the "going to sleep" arena).

The priority system in UNIX is one of those areas that can be confusing. Lowering the priority means raising the NICE value, which gives the process less CPU time overall compared to other processes with a lower NICE value and a "higher" priority.

Solidstate89: I think it is the opposite of what you are reading it to mean. That is, Apple is actively taking advantage of TurboBoost by running processes on as few cores as possible so that those few cores can run faster and get the job done sooner while the unused cores are shutdown to save power. At least, that is what I am reading it to mean.

Engineer A: "Hey, this feature of Linux is a pretty good idea. I wonder if we can implement our own flavor of this for the next iteration of OS X?"Engineer B: "Naw, we didn't come up with the concept out of whole cloth."

Mavericks prefers to use as few cores as possible, leaving others totally idle so long as demand allows it.

Doesn't this go against Intel's own philosophy of clocking everything up to 11 to finish the task as fast as humanly possible so the cores can go back to idle? This seems like what Qualcomm and nVidia tend to do on the ARM side of things instead of what Intel does.

Well, it probably depends a little bit on how the programs are coded. The OS can't parallelize a program automatically, but it can leave the other cores idle so you get a nice turbo boost. If there's demand for more threads, I'm sure the OS will utilize more cores.

Mavericks prefers to use as few cores as possible, leaving others totally idle so long as demand allows it.

Doesn't this go against Intel's own philosophy of clocking everything up to 11 to finish the task as fast as humanly possible so the cores can go back to idle? This seems like what Qualcomm and nVidia tend to do on the ARM side of things instead of what Intel does.

Actually, with Intel's Turbo Boost, it seems as though it might work quite well. Since Mavericks will put as much on one core as possible while leaving the others idle, the processor will be able to clock that one core up faster.

Is there any info on whether the new power management features would be compatible with the current Macs? My 2011 MBA could really do with some extra battery saving routine.

I think the vast majority of what is being introduced are just software changes, so all 10.9-compatible system should see some benefit, but anything Haswell should still trump all of them in overall battery life due to architectural changes.

10.9 looks great, but I *HATE* the name. It is not a name that rolls off the tongue. WHY is it in plural form?

Because the origin of the name was actually Maverick's, it was possessive. (Maverick was a dog.) Familiarity and use led to the apostrophe getting dropped.

It's an odd name choice to me too, because to those who are familiar with name/place it invokes images of asshole locals who will fight outsiders who come to surf and famous incidents where pro surfers were killed by the brutal waves there.

Engineer A: "Hey, this feature of Linux is a pretty good idea. I wonder if we can implement our own flavor of this for the next iteration of OS X?"Engineer B: "Naw, we didn't come up with the concept out of whole cloth."

Your point is valid. However, the reason people take this attitude because Apple often claim to invent things they merely evolve (or copy sometimes). This particular instance does not appear to be the case though.

Engineer A: "Hey, this feature of Linux is a pretty good idea. I wonder if we can implement our own flavor of this for the next iteration of OS X?"Engineer B: "Naw, we didn't come up with the concept out of whole cloth."

Your point is valid. However, the reason people take this attitude because Apple often claim to invent things they merely evolve (or copy sometimes). This particular instance does not appear to be the case though.

Looks like it needs to be explicitly enabled by each developer, by using specific APIs. I wonder if Apple's approach affects older code as well? I think in Windows this ends up not being taken advantage of because developers are not pushed to use it, Apple has always been more than willing to force developers into newer processes.

I agree with people that don't like the name; I'm pretty sure there are a bunch of other cat names they haven't used, and plenty of other cat-types (e.g - Wildcat) that could be used without breaking the flow. Mavericks is just an odd name, especially for an operating system. Cats at least kind of imply power, but a surfing hot-spot implies… wetness? This OS iteration is especially wet? I dunno. Even their joke "Sea Lion" would have been better IMO.

Still, I'm exited for the release; interaction notifications alone is a pretty sweet feature, but the attention on improving responsive is a big deal, even for those of us that actually only use desktop macs. I like browsing news and image sites in Safari, which can mean 20-50 open tabs before I stop to work through some of them when I release just how much CPU and RAM that leaving them open is wasting. It's pretty crazy that they haven't done anything before now, but as is sometimes the case with Apple this delayed feature is actually turning out to be a pretty important OS level feature instead (App Nap), so I'm not too annoyed in the end.

The Finder improvements are welcome, but I was still hoping for an actual overhaul, as it's still not the greatest app. At the very least it needs a rethink on touch and gestures to make it more efficient; bung in some keyboard command equivalents and I could love the Finder. Tags are nice to have as a proper feature, as opposed to me just adding keywords to the Spotlight comments box; though I'm probably now going to have to write an app/script that can find all files with comments set and upgrade them to use tags instead

Looks like it needs to be explicitly enabled by each developer, by using specific APIs. I wonder if Apple's approach affects older code as well? I think in Windows this ends up not being taken advantage of because developers are not pushed to use it, Apple has always been more than willing to force developers into newer processes.

The impression I got for Apple's Timer Coalescing is that it will probably stick within its documented tolerances for timers. That said, I'm hoping the ability to override this also comes with options to instead tweak it by expressing the ability to tolerate more or less delay in timers; i.e - a calendar app could probably stand up to five seconds of timer delay without much of an issue, but another app may only tolerate very short delays (but is still happy to be coalesced).

I'm glad this update is focusing on such optimisations. At this point, the two main priorities for OSes are security and power consumption, IMHO. Mavericks is just a terrible name though, Apple really missed an opportunity by not going with Sea Lion: the latter would have suggested lateral thinking, lightheartedness, and a sense of humour. Mavericks sounds like something Intel or Microsoft would have come up with; with all due respect to those two very impressive companies, it's fair to say that they have cultivated a different, more sober business-oriented public image.

While I am not a huge fan of the name either. It does feel right out of their Think Different campaign. Which some sources said was aimed more at employees than it was the public, to help bring back the original spirt of the company after Jobs came back. So could be something similar here.

The real question is how much is this going to affect non-Haswell MacBooks. Since those items don't sound particularly Haswell centric (other than the last one possibly, although that too should be possible on other platforms like Sandy Bridge and Ivy Bridge, albeit with less ROI because of the lesser capabilities of those CPUs in the "going to sleep" arena).

I actually wonder whether the OS features compensate for other CPUs' slower on/off switching by requiring less of it. If a CPU were able to switch instantly/powerlessly, the clustering, for example, would be irrelevant.

PS: a quick trip to the Airs' Tech Spec pages puts the usual weasel-word caveat on their claimed battery life, but “pre-production OSX 10.9” was not part of it. And the batteries appear to have the same capacity as the mid-2012 models. So I'm gonna guess Haswell gets a big slug of the credit for the Airs' better battery life.

Meanwhile, I'm gonna hope that Mavericks works its marvels on my trusty 2010 MBP/17; it could use some better life, especially considering its serious weight.

Ok. It's from Windows. That's cool. I think my point still stands though. I was trying to addressing the notion that having a feature not be 100% an original concept is somehow bad, rather than the specific timer coalescing feature.

Since Safari sucks in that it is a memory and processor hog, I actually wrote an AppleScript that puts the Safari processes to sleep when it moves to the background and wakes it when it is in the front again.

One area where this really helps is that web pages with crappy javaScript that bloat memory, simply don't, so that I don't have Safari using up 8 GB of RAM on my laptop.

Ideally, when in the background, javaScript should most likely be disabled and turned back on when it is in the front again.

Engineer A: "Hey, this feature of Linux is a pretty good idea. I wonder if we can implement our own flavor of this for the next iteration of OS X?"Engineer B: "Naw, we didn't come up with the concept out of whole cloth."

Your point is valid. However, the reason people take this attitude because Apple often claim to invent things they merely evolve (or copy sometimes). This particular instance does not appear to be the case though.

Sorry, the proof is in the pudding. Which laptops have the best battery life? Which will continue in to have the best battery life in the future? I'll give you a hint: they are made by the company with a fruit logo. If Apple copied these power saving features from Windows and Linux, why do Apple laptops have such better battery life? As a matter of fact, if you boot into Windows or Linux on an Apple laptop you still have better battery life than the competition, but still not as good as booting into Mac OS X.

Also I find it strange that folks are so quick to claim Apple copies others, but defend Samsung and Android as innovators. Again, the proof is in the pudding.

Engineer A: "Hey, this feature of Linux is a pretty good idea. I wonder if we can implement our own flavor of this for the next iteration of OS X?"Engineer B: "Naw, we didn't come up with the concept out of whole cloth."

Your point is valid. However, the reason people take this attitude because Apple often claim to invent things they merely evolve (or copy sometimes). This particular instance does not appear to be the case though.

As a matter of fact, if you boot into Windows or Linux on an Apple laptop you still have better battery life than the competition, but still not as good as booting into Mac OS X.

That's a complete fabrication. The drivers that Apple provides for Windows are of such poor quality that you can get literally twice the battery life from competing native Windows laptops. Especially those with switchable GPUs.

The gap isn't as big as you seem to think it still is. I've seen Ultrabooks get better battery life results than the MBA. Like HP's original take on the Ultrabook for example.