7

After simply recompiling our iPhone application on newly released iOS 5.0 SDK i faced strange problem - all UIImage:imageNamed (first call with actual image loading) and UIImage:imageWithContentsOfFile started to work 10 times slower than before. i managed to narrow problem down: this is the case only for jpeg and png files (not gifs!) and this is not because of file size. even straightforward loading of small 32*32 png takes around 300ms... compared to 30ms on older devices (checked on 3.1 and 4.3.5 with the exact same code)

i also tried to load image via newly introduced CIImage with this code

WLLog(@"Data loading...");
NSData *imageData = [NSData dataWithContentsOfFile:path];
WLLog(@"CIImage creation...");
CIImage* cii = [CIImage imageWithData:imageData];
WLLog(@"CIImage creation ok...");
float scle = 1.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    scle = [[UIScreen mainScreen] scale];
}
#endif
CIContext *context = [CIContext contextWithOptions:nil];
UIImage* res5 = [[UIImage alloc] init];
WLLog(@"UIImage creation...");
[res5 initWithCGImage:[context createCGImage:cii fromRect:cii.extent] scale:scle orientation:UIImageOrientationUp];
WLLog(@"Done!");

without any luck... this single line

CIImage* cii = [CIImage imageWithData:imageData];

takes the same 300ms even on small images (4Kb png). imho, there is simple nothing to parse at all!

Is there anything to resolve such strange change in loading times? For now it looks like something changed drastically in sdk internals :(

IPv6
  • 405
  • 4
  • 17

2 Answers2

8

I had the same problem and it took me a few hours to find out what went wrong. Our two situations seemed to be exactly the same: An old project that didn't run very well on iOS5 any more.

So I took Instrument's Time Profiler and dug into the depth of my app only to find out that every time the app hung it actually was in the process of opening PNG files for UIImageViews, just like you found out as well. But other apps I wrote don't have this problem, and I did everything the same way. So judging by what you experienced and that my other apps were running fine, I figured it must have something to do with the PNG files themselves. And guess what, it turned out that I was right.

So I sat down and wrote a script that piped all PNG files through ImageMagick's convert to make TGAs out of them, then deleted the PNGs (just for good measure) and then converted the temporary TGAs back to PNG files. That way I made sure that they were not only NOT created by Photoshop any more, but also completely rewritten.

That did the trick. Everything runs smoothly now, just as it did on iOS 3 and 4.

I'm not sure if it had something to do with Photoshop. Other apps I recently did work fine with PNGs made with Photoshop. So maybe it was the version of Photoshop I used pretty much exactly a year ago to create those PNGs in the first place.

Or maybe simply overwriting the old image files were enough, I'm not sure. But now it runs just fine.

I hope this helps!

Martin
  • 215
  • 4
  • 9
  • thanks, i will definitely give it a try and post here if it helps. anyway seems like a bug for me (things not better with newly released 5.0.1) and i`ll file it to Apple soon – IPv6 Nov 04 '11 at 03:39
  • So, have you tried it yet? Did it work with you as well? - I did a few more tests that confirmed that it had to do with reading the PNG from disk. Actually, judging by another Time Profiler trace that I did the biggest chunk of time is lost by iOS5 while creating the metadata class for the PNG that is read. – Martin Nov 05 '11 at 15:57
  • fantastic! Yes, this helps a lot, thanks! and your are right - seems like metadata is responsible for this crazines (both for jpeg and png). after re-saving all pngs and jpegs without metadata enabled all started to work as usual - images are loading in 30ms. seems like pre-5.0 ios SDKs just ignored any png/jpeg metadata – IPv6 Nov 07 '11 at 09:45
  • 2
    Here is screenshot of single photoshop save-for-web option, responsible to this problem (should be none). I found that this option is On by default in MacOs version of Photoshop and Off in Windows version of Photoshop, so this is worth paying attention https://lh6.googleusercontent.com/-R_VCI3ky9yQ/Trenrxsl-uI/AAAAAAAAFU4/pd66ZTLHKlQ/s778/Scr20111107_1257_%25231.jpg – IPv6 Nov 07 '11 at 09:49
4

It could very well be a bug. Submit a radar to Apple via the bug reporter. Be sure to throw together a simple project which clearly demonstrates the bug and attach it to the bug report -- otherwise Apple will send you an email asking for one.

Post your radar # here so others with a similar issue can reference that # when submitting a similar bug to Apple as well.

memmons
  • 40,222
  • 21
  • 149
  • 183