iosswiftframe-ratecadisplaylinkbattery-saver

How can I reduce the frame rate in a swiftUI app?


I'm looking to optimize battery performance by reducing the frame rate to 1hz. The app is a dashboard that updates only once per second, doesn't have animations and is not interactive. Is it possible to set the refresh rate of the OLED display to 1hz?

I tried setting a CADisplayLink in the app delegate but it didn't make a difference.

Apple mentions using this approach in WWDC 2022, but I just can get it to work in my SwiftUI app.


Solution

  • The refresh rate is a function of the entire screen. You cannot unilaterally control it yourself. Other things on the screen that are not your app (the status bar, the dynamic island) may need to update. Different screen technologies also require different minimum refresh rates in order to keep a sharp image. None of this is under your app's control.

    The minimum refresh rate for ProMotion displays, the common technology for higher-end Pro/Max devices, is 10Hz. I don't know of any iPhone or iPad screen that supports a 1Hz refresh rate.

    Your best way to optimize screen refresh performance in SwiftUI is to not invalidate any Views unnecessarily. The OS will tune the refresh rate based on that. If you are using SwiftUI and not invalidating your Views unnecessarily, then I would expect it to run at 10Hz on a ProMotion phone. I believe I've seen 10Hz on my non-ProMotion devices as well, but it's been a while since I audited it.

    You only need to employ CADisplayLink if you are doing your own custom rendering. You should avoid this if possible, but Apple gives you tools if you need them. For your situation (pure SwiftUI), the entire answer is "don't invalidate your Views more often then required." There is nothing else you can or should do.