Reputation: 37329
This operation takes 700 ms on iPhone 5 running iOS 7.1.2.
UIImage(data: data)
data
is NSData containing JPEG image, 400x300px 90K.
How can I make it load faster or it least not block the UI?
Demo app is here: https://github.com/exchangegroup/demo-image-loader-benchmark-swift
This slowdown only happens when I start the app on the device from Xcode. When started from the device itself it runs much faster, at about 20ms. First run is still much slower than subsequent runs, which are about 1ms.
Upvotes: 1
Views: 1892
Reputation: 1892
This will highly depend on the size of your images being loaded, what their original compression was, etc.
In general, you should NEVER base performance assumptions off of debug builds from Xcode, and that goes TRIPLE if you've got the debugger attached. If you want to see how fast something really is, you want to build and install to the device using the Release profile that comes with your project, and run the build without the debugger attached. Release builds are generally at least 1 order of magnitude faster, assuming you've followed standard procedures like wrapping NSLog so it doesn't spit out logs to the console for Release builds.
Upvotes: 5