Documentation Archive


Metal Best Practices Guide

On This Page

Frame Rate (iOS and tvOS)

Best Practice: Present your drawables at a consistent and stable frame rate.

Most apps target a frame rate of 60 FPS, equivalent to 16.67 ms per frame. However, apps that are consistently unable to complete a frame’s work within this time should target a lower frame rate to avoid jitter.

Querying and Adjusting the Frame Rate

The maximum frame rate of iOS and tvOS devices can be queried through the maximumFramesPerSecond property. For iOS devices, this value is usually 60 FPS; for tvOS devices, this value can vary based on the hardware capabilities of an attached screen or the user-selected resolution on Apple TV.

Using an MTKView object is the recommended way to adjust your app’s frame rate. By default, the view renders at 60 FPS; to target a different frame rate, set the view’s preferredFramesPerSecond property to your desired value.

Adjust the Drawable Presentation Time

The presentDrawable: method registers a drawable presentation to occur as soon as possible, which is usually at the next display refresh interval after the drawable has been rendered or written to. If your app can maintain its maximum target frame rate, as set via the preferredFramesPerSecond property, then simply calling the presentDrawable: method is enough to maintain a consistent and stable frame rate.

If your app targets a lower-factor frame rate, the display refresh rate (e.g. 60 FPS) may fire more frequently than your app’s render loop (e.g. 30 FPS). This means that the presentDrawable: method could present a drawable earlier than expected if a frame is rendered before the next display refresh interval (e.g. 16.67 ms intervals).

The presentDrawable:afterMinimumDuration: method allows you to specify a minimum display time for each drawable, meaning that drawable presentations occur only after the previous drawable has spent enough time on the display. This lets you synchronize your drawable’s presentation time with your app’s render loop. The relationship between the preferredFramesPerSecond and presentDrawable:afterMinimumDuration: API is shown in Listing 8-1

Listing 8-1Presenting drawables after a minimum display time
  1. view.preferredFramesPerSecond = 30;
  2. /* ... */
  3. [commandBuffer presentDrawable:view.currentDrawable afterMinimumDuration:1.0/view.preferredFramesPerSecond];