I’m a beginning to iOS development. My objective is to reduce load-time perception during application load. I’ve been adding “Start” “ended” flags all over my code to try and figure out where the delay is during my application load. Below is a list of function entry points and exits. My question is:
-
What’s happening after didFinishLaunchingWithOptions? Is there a function I missed?
1 entry: int main(int, char **) 2 entry: -[AppDelegate application:didFinishLaunchingWithOptions:] 3 entry: -[AppViewController loadView] 3 exit : -[AppViewController loadView] 3 entry: -[AppViewController viewDidLoad] 3 exit : -[AppViewController viewDidLoad] 3 entry: -[AppViewController viewWillAppear:] 3 exit : -[AppViewController viewWillAppear:] 3 entry: -[AppViewController viewDidAppear:] 3 exit : -[AppViewController viewDidAppear:] 2 exit : -[AppDelegate application:didFinishLaunchingWithOptions:] ? ?????: //Here i see a VERY LONG PAUSE, possibly loading the view into memory? //Anyway to reduce this time here? //After this long delay the view actually shows up on the phone.
I’m capturing this by littering my code with macros:
-
- (void)viewWillAppear:(BOOL)animated { MARKSTART; [super viewWillAppear:animated]; MARKEND; }
For those that might be interested, here are my macros. Adopted from the following webpage: http://www.dizzey.com/development/ios/6-useful-objective-c-cocoa-macros/
-
#define MARK NSLog(@"----%s", __PRETTY_FUNCTION__); #define MARKSTART NSLog(@"/===Entry: %s ===\\", __PRETTY_FUNCTION__); #define MARKEND NSLog(@"\\===Exit : %s ===/", __PRETTY_FUNCTION__);
Additional information:
- I have many buttons in the xib file.
- Controls are skinned by replacing the background color or image with something
- PNG Image loading actually happens in viewDidLoad, the disk IO is pretty fast
- The latest delay feels like when the “view” is actually being loaded into memory, but I can’t be sure.
Any advice on who i can dig deeper into this and find better ways to make my application load more quickly, or perceive that it loads more quickly? My biggest headache is the VERY LONG PAUSE… on iphone 3g (4.2.1 ios) it takes about 4.2 seconds.
Please advise,
Box
Additional Details based on Comments form the the thread. The following code in inside of ViewDidLoad. This happens very quickly taking about 200ms at the most:
wholeImage = [UIImage imageWithContentsOfFile:@"DefaultSkin.png"];
CGImageRef drawImage;
drawImage = CGImageCreateWithImageInRect(wholeImage.CGImage, CGRectMake(0, 0, 320, 480));
imageMainBackground = [[UIImage imageWithCGImage:drawImage] retain];
CGImageRelease(drawImage);
drawImage = CGImageCreateWithImageInRect(wholeImage.CGImage, CGRectMake(320, 0, 320, 480));
imageAnotherBackground = [[UIImage imageWithCGImage:drawImage] retain];
CGImageRelease(drawImage);
I continue this, cutting up the large “whole image” into buttons and controls. Also during ViewDidLoad, I will assign them to views and subviews, like this:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[GuiSkinManager sharedSingleton].imageMainBackground]];
Debugging output console shows ViewDidLoad with these NSLog outputs:
2012-02-10 12:43:11.150 App [1714:307] Entry: -[AppViewController viewDidLoad]
2012-02-10 12:43:11.467 App [1714:307] Exit : -[AppViewController viewDidLoad]
So the setup and cutting is only 310ms while debugging. But the image itself is not actually processed at this time?
So it seems that your problem is using
setBackgroundColorinstead of using aUIImageView. I would guess that’s becausesetBackgroundColoris meant for when you’re using a small image that is tiled rather than a single background image. AUIImageViewwill be super optimised for drawing a single image. I assume that’s what’s going on anyway.The moral of the story here is to use instruments. It’s a great tool that can really help track down a number of problems. The “Time Profiler” instrument is a great help when working out what’s taking up CPU time.