SwiftData app always at 100% cpu when idle after upgrading to Xcode 15.3

Our app is using SwiftData + SwiftUI. After upgrading to Xcode 15.3 Beta, RC1, RC2, we’ve experienced the same issue that the app is having 100% CPU activity even when left idle. This happens as long as the SwiftUI is using @Query to fetch SwiftData and the query does return at least 1 result (there is no issue if the query returns empty result).

We’ve tried the following and therefore confirmed that this is a Xcode 15.3 beta issue:

  • Xcode 15.3 Beta + iOS 17.2 -> 100% CPU activity when idle
  • Xcode 15.3 Beta + iOS 17.4 beta -> 100% CPU activity when idle
  • Xcode 15.2 Beta + iOS 17.2 -> normal

This only happens during debug run. When profiling / using instrument, this doesn't happen.

More info:

Xcode 15.3 stable release + iOS 17.3 -> 100% CPU activity when idleXcode 15.3 stable release + iOS 17.4 stable -> 100% CPU activity when idleXcode 15.2 + iOS 17.4 stable -> normal

I am seeing something similar, but not exactly the same.

My app is also using SwiftUI + SwiftData. When running debug on Xcode 15.3 (release) + iOS 17.4 simulator I'm seeing 100% (or greater) CPU when typing into a TextEditor that is bound to a SwiftData model object. That model object is part of a @Query. If I'm not typing, however, the CPU returns to 0%.

I just tried the same using Xcode 15.2 (release) + simulator on iOS 17.4 and the CPU is much more in line with expectations.

I have not tried this on a device (rather than simulator). I'll try the device when I get to my desk.

Frustrating.

Same here. I have a swiftData app, that was working fine. Upgraded to XCode 15.3 stable last night, and suddenly CPU usage is basically 100%, in the simulator (iOS 17.4) even when the app is just sitting idle. Downgraded to XCode 15.2, and the problem is gone. CPU usage ~1% when idle.

Forgot to mention, this was both on a device, and in the simulator.

Same.

I too have noticed one core running constantly at 100% while running Xcode 15.3 and iOS 17.4. Although I'm not using SwiftData. Anyhow, I've noticed that I can bypass this issue by disabling both Main Thread Checker and Thread Performance Checker in the Scheme's Run target Diagnostics tab.

Just in case it helps anyone out.

I have the same issue on UIKit app with UITableView and UICollection with diffable datasource. On Xcode 15.2 everything is ok, but on Xcode 15.3 when the scrollviews are moving some random thread starts have 100% CPU for a while.

Glad to see other people are facing the same issue with swiftdata, I've been coding for a week straight trying to figure out in my settings and codes why I was facing this issue. My CPU goes between 100% and 200% when using the app with my swiftdata. Whenever I remove swiftdata from the data my app works normally. I even tried to use Product - Profile - Instruments - Time Profiler, and the issue is pointing at swiftdata getter. At the beginning I was getting a white screen whenever opening the app for the first time from the compiler on both simulators and phone. I improved the cpu usage a bit but now it's still running between 100%-200% with extreme lags that make the app impossible to use. I was ready launch the app and then i upgraded to the new xcode version and everything went downhill. Overall in my other apps I also had a lot of issue having to refactor some codes that used to work in the prior xcode version (good practice i guess but kind of annoying). Looking forward to an update that will fix this issue! Thanks to the dev team working on this.

Having the same problem, but only when running the simulator. CPU jumps up to 180%. It's constantly re-running my @Query in one of my views and I have no idea why, doesn't do that on my physical device.

Me too, 170%, when idle, especially when the real machine is debugged, it is easy to have problems, a lot of bugs, easy to get stuck, and there is no error, I don't know if it is blocked. It is easy to crash and is not suitable for binding directly to components, especially $ bindings

Having similar performance problems here too. Discovered that it only happens when the "Debug executable” checkbox in the run scheme is turned on (the default). The performance degradation becomes really obvious when accessing SwiftData properties repeatedly such as when sorting objects from a one-to-many relationship using a sortOrder property, for example. Hitting pause when it is hung for a while almost always shows up in the getter for that property inside the sort. Also the temporary hangs get longer and longer each time that sort code is run again and memory ramps up each time too so there is some kind of memory leak. Ironically, there are no performance issues at all when running the app in Instruments or when running independently of Xcode or with the Debug executable checkbox turned off (but then breakpoints don't work and the builtin CPU, memory, etc. graphs don't show). I wrote an Apple feedback ticket for it: FB13707023.

On the plus side, I spent the last few days optimizing my app (lazy getters for the relationship sorting, algorithm tuning, etc.) because this issue really amplifies/exaggerates the less efficient areas of your code and now it runs lightning fast when it's not connected to Xcode! 🙃

I am experiencing the same problem.

The way to reproduce it is simple, just create a simple Model in SwiftData, query it in View and display it in Swift Charts.

When I start the app, the display is instantaneous, but then the CPU shows 100% for a few seconds.

Xcode Version 15.3 (15E204a)

I'm also experiencing this issue. The CPU is slowly moving up about 1% every second, until it reaches >250%. Disabling both Main Thread Checker and Thread Performance Checker in the Scheme's Run target Diagnostics tab will resolve it.

Glad to read others are having the same issue, got scared for a but. Also using SwiftData. If you run your App in instrument it's fine.

Similar issue! The joys of coding.

SwiftData app always at 100% cpu when idle after upgrading to Xcode 15.3
 
 
Q