I'm wondering how costly are I/O operations in iOS.
Let's assume I have application that download images from urls and store it in device memory.
Downloading of course is made asynchronously, but I'm wondering about storing data in device memory and about receiving it from memory.
There are a lot of small images (thumbnails), but I'm also store big images (1-2 MB).
Should I make write and read operation asynchronously on background thread, or it will not have that much impact to performance if i make it on main thread.
Since you are already downloading the images asynchronously, it isn't much more difficult for you to also store them asynchronously. And I would say it is a best practice, because it has nothing to do with UI stuff so it shouldn't be on the main thread.
Check out this doc from Apple. They do not specifically say that storing files should be done on a background thread, however they acknowledge that it can be a pretty costly operation when you have a lot of files (and more so when we're talking about images...)
If your app works with a lot of files, the performance of its file-related code is very important. Relative to other types of operations, accessing files on disk is one of the slowest operations a computer can perform. Depending on the size and number of files, it can take anywhere from a few milliseconds to several minutes to read files from a disk-based hard drive.
They also give you lots of nice tips to reduce I/O operations - like reusing the NSURL objects - that you can easily adopt in your coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With