macOS Energy Efficiency Guide

From Lazarus wiki
Revision as of 08:22, 19 February 2021 by Trev (talk | contribs) (First draft - work in progress)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
macOSlogo.png

This article applies to macOS only.

See also: Multiplatform Programming Guide

English (en)

Warning-icon.png

Warning: Work in progress

Overview

All applications consume energy whenever they update the user interface, perform networking operations, write to disk, or run code on the CPU. As users rely increasingly on battery power energy efficiency becomes integral to the user experience.

macOS employs advanced energy-saving technologies to help users get the most out of their Macs. These features help the operating system make smart decisions about how to use resources and run code as efficiently as possible.

Quality of Service Levels

Tasks that affect the user, such as downloading and playing music, take priority over background and discretionary work. Quality of service class APIs allow you to assign distinct priority levels to the work your application performs, giving you fine grained control over task prioritization.

Event-Based APIs and Services

Timers deliver events, or fire, at prescribed time intervals. If a timer fires when the system is idle, the CPU and numerous other systems awake from their low-power states. Yet many of these systems aren’t always needed to perform the work invoked by the timer. If the work can be performed when the system hardware is already running, the additional cost is not incurred and the CPU can remain idle longer. macOS provides services and APIs that efficiently deliver events without unnecessarily waking the CPU.

App Nap

When your application is not busy performing user-initiated work, the system may put it in App Nap. App Nap conserves energy by regulating your application’s CPU usage, I/O, and timers. As soon as the user resumes interacting with your application, macOS switches it back to full speed. Transitions are so seamless that the user thinks your application has been running at full speed all along. You can enhance App Nap by implementing notifications that tell your application when it becomes inactive, so it can immediately start reducing activity.

For further details about App Nap, including FPC code, see macOS App Nap.

Activity Monitor, Instruments

The Activity Monitor application lets you quickly identify applications that are using significant amounts of energy in macOS. The Xcode Instruments application, and numerous command-line tools, help you identify and address energy problems as you develop your application, rather than after those problems are encountered by users.

External links