SwiftUI dropping state changes silently?

Hello all,

I have an app that demonstrates how sorting algorithms work. It's written in SwiftUI and uses native geometry objects (Rectangle, etc.) to draw the bars that are demonstrating the sorting algorithm.

The application runs just fine on macOS Sonoma and iPadOS 17, if not a little bit slowly because the algorithm and drawing are interlocked to stay in time. When I started working on the app in Xcode 16 and running it on macOS Sequoia, I notice a very unusual change: the algorithm is running significantly faster (104.5 "operations" per second in Sequoia vs. 78.5 in Sonoma), with the nebulous side effect of the visualization noticeably stuttering. The application sometimes looks like it's frozen because several underlying state changes are being reflected in the UI, and when the sorting process is completed, it's supposed to turn all of the rectangles green, but this doesn't happen on the Sequoia/Xcode 16 build unless I open the navigation pane after sorting is completed.

I can't find any reference to behavior changes in SwiftUI like this. Is this expected behavior? I thought that if such a significant change was made to SwiftUI's behavior, then Apple would at least inform their developers that they need to adapt their code in an article or a WWDC video.

I did file a bug, it's 14025421 in Radar (don't know the correct format for Radar links). I included examples of how the app is supposed to look, along with some source code, and a large number of Instruments traces. I attempted to debug from there, but nothing was out of the ordinary; the traces were almost identical between the release version that runs on Sonoma and the debug build version that runs on Sequoia.

Here's the behavior between the two versions on display, for reference. You might have to copy and paste the links, because the editor told me I wasn't allowed to have links to YouTube for whatever reason.

  • Expected behavior, where animations are smooth, but algorithm runs more slowly: https://www.youtube.com/watch?v=UWMXiju8EMg
  • Unexpected behavior, where sort algorithm performance is higher, but animations are choppy, and state changes are skipped: https://www.youtube.com/watch?v=GB0VJo8W7_0
SwiftUI dropping state changes silently?
 
 
Q