0

I have a segue that takes just over a second to perform. The destination view controller is rather big, but even if I comment out the entire viewDidLoad function, it still takes this much time. Can this happen from having too many properties and imports alone? (I have around 30 of each)

This is a trace of the events on a relative time frame:

00:00:00.000 Performing segue
00:00:01.297 View did load
00:00:01.315 View did appear

Things I have tried:

  • Emptied viewDidLoad
  • Emptied prepareForSegue
  • Making sure the segue is being run in the main thread
  • Emptied viewWillAppear (not that it should make a difference)

I am running this on an iPhone 6 Plus.

Edit:

The segue is being performed like this:

- (void)checkForPermissions
{
    [self.permissionsUIGateway checkCameraPermissionSettingsFromViewController:self completionHandler:^(BOOL granted) {
        if (granted)
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self performSegueWithIdentifier:@"goToCamera" sender:self];
            });
        }
    }];
}

Edit 2:

I have found out that either using presentViewController:animated:completion or changing the segue from Present modally to Show makes the delay completely disappear. This solves my problem, but I will leave the question open since I still have no idea why this solves it.

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
  • I imagine it is due to your properties and imports. Could you try making some of your properties lazy to see if that fixes the problem? Especially if you think they are computationally intensive. Swift makes it easier, but you can look at this to make the properties lazy: http://stackoverflow.com/questions/11769562/lazy-instantiation-in-objective-c-iphone-development. – anders32 Jun 03 '16 at 00:55
  • @anders32 Almost all properties are either injected dependencies (DI is done using Typhoon) or IBOutlets. The rest of them would effectively be lazy from me commenting out viewDidLoad. – Daniel Larsson Jun 03 '16 at 01:02
  • So you're initializing all of the properties in viewDidLoad? If that's the case then what happens if you comment out all of your libraries? – anders32 Jun 03 '16 at 01:06
  • Have you used the time profile instrument to see where the time is being spent? How do you trigger the segue? Can you show that code? I know you said that you have verified that it is being performed on the main queue, but the information you have shown is classic stuff being performed on a background queue. Also, are you using any custom or non-standard fonts in the destination view. This is also known to cause delays – Paulw11 Jun 03 '16 at 01:27
  • Or you could be triggering the segue on a background thread... – matt Jun 03 '16 at 01:57
  • @Paulw11 I will run it in the time profiler later tonight. I am using a custom font in the destination view, yes. I didn't know that could cause performance issues – Daniel Larsson Jun 03 '16 at 02:53
  • @Paulw11 Why is that? Is it because the font doesn't really get loaded until it is actually used? – matt Jun 03 '16 at 03:49
  • It seems to be that if the font name isn't quite right then iOS somehow has to scan the entire font catalog to find the font or a suitable substitute. It is definitely known to be a problem in SpriteKit but I seem at least one other question on SO where the custom font was the cause of slow scene loading with UIKit – Paulw11 Jun 03 '16 at 04:07
  • And yes, it is lazy loaded. In the case of the other question I referred to, the asker came up with a work around that involved loading the font earlier so that the delay wasn't noticeable – Paulw11 Jun 03 '16 at 04:11

0 Answers0