Hi marchyman,
I'm guessing there are other methods being called by static AppName.$main() [inlined]
, but they might be framework functions and thus collapsed by default, depending on which view you look at.
If you look at the heaviest backtrace view on the bottom right, you can click the small bottom at the top right of that backtrace view to toggle showing callings from functions that are not part of your app, e.g. from system frameworks. Sometimes this can give you a hint at what might be going on and what you can optimize.
If you can post a screenshot of your Instruments trace document, we can help you interpret it.
However, you mention SwiftUI, so here are some additional guesses what might help:
What SwiftUI view are you using specifically? You are talking about a "table". Are you really using the SwiftUI Table
view, or maybe making something that looks like a table using a List
or maybe VStack
or Grid
?
List
and Table
should be lazy and only compute as many bodies as are needed for one screenful of content, so their performance shouldn't change much if you have 100 or 1200 elements (assuming less than 100 fit on screen at once).
Given that you say the number of elements makes a difference you are likely either using a non-lazy view (like Grid
or VStack
), in which case switching to the lazy variant might be an option. Take a look at Stacks, Grids, and Outlines in SwiftUI, which talks about some of these cases.
I you are already using a lazy view, it might be that the collection you pass to ForEach
takes a long time to compute.
E.g. for code like this:
List {
ForEach(model.loadAllItemsToDisplay()) {
// the contents of each list item
}
}
If loadAllItemsToDisplay
would take a long time to run you'd see an effect like this. However, if loadAllItemsToDisplay
were implemented in your code, it should also show up in the heaviest backtrace then, so it's a bit unclear what's happening in your case without more information.
Another instrument that might be useful in you case is the "SwiftUI View Body" instrument. You can add it to your document by clicking on the + button in the top right, which shows the "Instruments Library" and then searching for "SwiftUI" in there. Simply drag the "View Body" instrument to your document and record again.
The "View Body" instrument should show you each view body that gets executed and maybe gives you some insight into which one takes a long time.