https://github.com/poomsmart/cahighfps
Make your CoreAnimation applications use the highest available FPS.
https://github.com/poomsmart/cahighfps
Last synced: 5 months ago
JSON representation
Make your CoreAnimation applications use the highest available FPS.
- Host: GitHub
- URL: https://github.com/poomsmart/cahighfps
- Owner: PoomSmart
- License: mit
- Created: 2021-10-02T00:43:26.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-11T03:33:42.000Z (over 1 year ago)
- Last Synced: 2025-02-09T15:14:45.992Z (over 1 year ago)
- Language: Logos
- Size: 26.4 KB
- Stars: 33
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CAHighFPS
Makes your CoreAnimation applications use the highest available FPS.
## Part 1: CADisplayLink
Quoting from [Apple](https://developer.apple.com/documentation/quartzcore/cadisplaylink), `CADisplayLink` is a timer object that allows your app to synchronize its drawing to the refresh rate of the display. A5 devices (iPhone 4s and iPad 2) are the first to introduce 60 HZ refresh rate - and that the applications can run at its best at 60 frames per second (FPS).
### Frame Interval
There is a (now-deprecated) property of `CADisplayLink` called `frameInterval` that the developers can set to limit the FPS. If set to `1`, the FPS is 60. This is true according to the underlying logic of `setFrameInterval:` method:

Some applications out there choose `2` as a value, rendering the final FPS at `60/2 = 30` which doesn't sound cool for the devices that are capable of higher FPS.
This is where CAHighFPS enforces the value of `frameInterval` to be `1`.
### Preferred Frames Per Second
It is a substitute `CADisplayLink` property of `frameInterval` (until iOS 15.0), goes by the name `preferredFramesPerSecond`. If set to zero, the system will try to match the FPS to the [highest available refresh rate of the device](https://developer.apple.com/documentation/quartzcore/cadisplaylink/1648421-preferredframespersecond).
Here's the underlying logic of `setPreferredFramesPerSecond:`:

Again, some applications can explicitly set it to `30` or `60`. Those devices that are capable of higher than that will not be so pleased.
This is where CAHighFPS enforces the value of `preferredFramesPerSecond` to be `0`.
### Preferred Framerate Range
Introduced in [iOS 15](https://developer.apple.com/documentation/quartzcore/cadisplaylink/3875343-preferredframeraterange?language=objc), this is now their main way of dictating the effective FPS. As we want to ensure the maximum FPS, the property `preferred` and `maximum` of `CAFrameRateRange` will be set to the highest supported FPS by the device.
## Part 2: CAMetalLayer
Metal has been a thing since iOS 8. For some reasons, there are not a lot of discussions about optimizing Metal apps for ProMotion display. The best I found are to override `-[CAMetalLayer maximumDrawableCount]` ([reference](https://blog.csdn.net/ByteDanceTech/article/details/123437098)) and `-[CAMetalDrawable presentAfterMinimumDuration:]` to allow for ideal ProMotion FPS.
## Everything Else
### Battery: Does it drain your battery?
Because CAHighFPS enforces the highest available FPS for the apps, it's only natural that this will consume more energy. Draining may be significant or else. YMMV.