When I first load my app, where are the assets for, say, images, located? Is it somewhere where loading them in the UI is never a performance issue and can always be done in the main thread? (e.g. even if there were 100 assets loaded at once) I’m assuming it’s safe to load assets from asset catalog in main thread but I want to double check and also learn more.
Where are the asset catalog resources stored at runtime?
The contents of your asset catalog are compiled during the build. If you inspect the inner contents of your .app package, you'll see a file with the .car extension, which is the result of the asset compilation steps in the build.
You generally load assets on the main thread — especially for something like an image that is displayed in the UI immediately — because that is a UI operation, and UI operations always need to be on the main thread.
In a hypothetical scenario where you find your app is slow, and the scenario happens to involve loading the 100 images you reference, the first thing you'd do is profile your app to understand why it hangs using Instruments to get data on how your app was spending the time. The data is important, because you wouldn't want to prematurely optimize without understanding where the bottleneck in performance is.
— Ed Ford, DTS Engineer
Why is it generally fast to load the assets on the main thread? How about normal files stored using the File Manager?
It's not necessarily an absolute that loading assets on the main thread is faster than loading them on any other thread. There's a lot of "it depends" here, based on how the loaded asset is going to be used once loaded. Your example is focused on UI elements, so a straight-forward use of loading the assets from the asset catalog with UI based image APIs (such as Image or UIImage) is the best place to start, because that is a highly used path by all apps. For that scenario, there's no reason to complicate the loading code until you have a demonstrated performance issue where you have data from Instruments to pinpoint what needs to be addressed. Even if you are loading an image by constructing a local URL from FileManager and then passing immediately that URL to Image or UIImage to display it, I'd still start with the same advice until there's a clear performance issue where you need to reconsider the approach.
— Ed Ford, DTS Engineer