UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How Costly is @Query?

Forums > SwiftUI

With SwiftData, how costly is @Query? I am creating an app that is currently heavily reliant on @Query. Would it be better to use an @Binding array between views to limit the number of queries, or is the performance impact of a query negligible?

Feel free to ask any follow up questions if necessary.

An Inconclusive Update

Thank you @Obelix, I used the Instruments tool in xcode, and was able to fix my performance issues. I had a few functions in my app that would cause the app to hang. I changed them to run on a background thread and the performance has much improved since then.

I did not have to change any of my @Query relationships to @Binding. I'm still learning how to use the Instruments tool, and although I was unable to figure out the performance impact of a query quantitatively, my current conclusion is that a heavy usage of @Query is not a problem

2      

@wingman thinks he may be buzzing the tower too often...

With SwiftData, how costly is @Query?
is the performance impact of a query negligible?

Instruments to the Rescue

Apple supplies a number of external monitoring tools to find animation chokepoints, launch time delays, network activity, audio performance, memory leaks, wasted disk space, and more. In Xcode, find the Open Developer Toolmenu, then open Instruments.

You're looking for an Instruments profile that traces filesystem activity, including database faults, fetches, and saves. Lucky for you, Instruments comes with one called Data Persistence.

This is where my knowledge ends. I've never setup an Instruments profile to document my applications' performance. Maybe there are tutorials on web describing Instruments? This is your adventure now.

Keep coding!

Please update your post, if you found Instruments to be useful.

WWDC Link

See -> WWDC Instruments

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.