SwiftUI animation stalls when main thread is blocked
For developers using Apple's frameworks, this explains a key difference in how SwiftUI and UIKit handle animations under load, which can affect app performance and user experience.
React Native developer Krzysztof Magiera demonstrated on X that when the main thread is blocked, SwiftUI's animated ball freezes, while UIKit's ball continues smoothly.
The reason is that SwiftUI does not use Core Animation, the engine that has made iOS animations smooth since the first iPhone.
Its creator Kyle Macomber responded that this is one of the team's earliest design decisions.Core Animation runs animations in a separate render process, isolated from the app process, which prevents stalling.
However, this makes it difficult to implement interactive, interruptible animations like list scrolling or app switching gestures.
SwiftUI runs animations in the app process to make such interactions the default, not a special case.Macomber also noted that SwiftUI's animations mostly run on non-main threads, contrary to the demonstration.
React Native 开发者 Krzysztof Magiera 在 X 上发了一个技术演示:主线程被阻塞时,SwiftUI 的动画球会卡住,而 UIKit 的球照样平滑运动。原因是 SwiftUI 没有使用 Core Animation,那个从初代 iPhone 起就让 iOS 动画丝滑的底层引擎。他的结论是,SwiftUI 称不上"真正原生"。 SwiftUI 的共同创建者、苹果工程师 Kyle Macomber 很快回应:这是团队最早期、最根本的设计决策之一。 Core Animation 之所以不怕主线程卡顿,是因为它的动画跑在一个独立的渲染进程里,和 app 进程完全隔离。但代价是:当你希望用户在动画过程中随时打断并交互,比如列表滚动时的回弹、主屏幕切换 app 的手势,实现起来非常困难,因为事件处理和动画不在同一个进程。 SwiftUI 把动画放回 app 进程,就是为了让这类可交互、可中断的动画成为默认能力,而不是需要开发者费力实现的特例。Macomber 还指出,SwiftUI 的动画大部分时间实际上跑在非主线程上,并不像演示暗示的那样总会卡。 Krzysztof Magiera @kzzzf SwiftUI isn’t native and here’s why SwiftUI apps may sometimes feel janky. It ditches the key element that made animations run so smoothly on iOS since the original iPhone: Core Animation. In SwiftUI animations run in-app without CA backing. Block the main thread: SwiftUI ball stalls while UIKit’s keeps moving on the render server.
This report is categorized under AITOP's "How-to" desk, focusing on US frontier AI labs and Silicon Valley technology leaders. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows. Key entities and technical topics under continuous tracking include SwiftUI, UIKit, iOS, animation.
Source attribution: curated from 宝玉 (@dotey).