Skip to content

esnssr/frame_rate_swiftui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUI Frame Rate Shenanigans

i have noticed that the behavior for running animations on SwiftUI is different than UIKit. i was working on a simple sheet-like presentation animation in SwiftUI when i noticed the animation is not smooth when running on physical device? i suspected that maybe i am doing something wrong.

looked it up online, and found this post (which i have seen two years ago) talking about the same issue. i didn't have the CADisableMinimumFrameDurationOnPhone key, so i added that, but still my issue was still not fixed. SwiftUI was still dropping frames on the physical device.

i quickly made a small demo project, and added the exact same animation for both UIKit and SwiftUI for 1 second, even though in my original animation i was using 300ms. i immediately noticed the difference when running both animations (UIKit and SwiftUI) side by side. instruments shows that SwiftUI drops to 16ms (60Hz) on my iPhone 14 Pro (which supports 120Hz Pro Motion) while UIKit doesn't and moves with 8ms.

if you are not familiar with timings and refresh rates for Pro Motion displays take a look here.

anyways, i am now desperate 😅. i am trying to avoid using UIKit here (or maybe i will? 👀), so i would appreciate any help here!

you can see the difference by downloading and running the project in this repo, or copy paste the contents of this file to your own created project. you have to run it on a physical device to see the issue. then:

  • toggle SwiftUI view animation, notice how the view animation glitches a little bit. the behavior can sometimes be inconstant, but if you run the animation multiple times you will %100 see it dropping to 60Hz.
  • try to run toggle the UIKit view animation. this will always run smoothly on 120Hz.
  • try to toggle both. sometimes SwiftUI will drop to 60Hz and sometimes it doesn't. but toggling the SwiftUI view you will almost always see it dropping to 60Hz.

peviews 📺

i don't think the videos here make the difference clear, but here are some previews of the issue.

SwiftUI

IMG_2200.3.MOV

UIKit

IMG_2201.2.mov

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages