13

I am optimizing a transition that seems to be slow on my device. I am pushing one UIViewController from another when a UITableView's row is selected. There is a noticeable pause after row selection and before the new view is pushed.

Some logging indicates that all of my code is reasonably quick, from row selection until the pushed controller's viewWillAppear. But then the time between viewWillAppear and viewDidAppear is logged at around 0.7 seconds.

The transition itself (I believe) should only take 0.3 seconds. What could be accounting for the remainder?

I am testing on an iPhone 4, so I'm not expecting the snappiest performance. But I should be able to match the same performance of other similar apps on the same device, no?

4
  • Did you override the layoutSubviews method of your controllers view? If so, do you have complex logic in there?
    – Nenad M
    Commented Oct 20, 2012 at 19:00
  • @JackyBoy I wouldn't know what to post, since I'm not sure what is being executed between the two. Commented Oct 20, 2012 at 19:00
  • @NenadM I haven't overridden layoutSubviews Commented Oct 20, 2012 at 19:01
  • Maybe you have overridden viewWillLayoutSubviews?
    – roop
    Commented Jan 15, 2013 at 8:15

2 Answers 2

2

I had a similar question a few weeks ago, and I wrote a blog post about what I found:

http://bradbambara.wordpress.com/2014/07/31/object-life-cycle-uiviewcontroller/

The TL;DR version is that iOS will:

  • perform the layout of your new scene
  • perform the transition to your new scene (if it's an animated transition)

...so my guess is the delay could be caused by an especially long transition, or if you're doing any performance-intensive work in your layout code.

1

The transition itself (I believe) should only take 0.3 seconds. What could be accounting for the remainder?

Resources are usually consumed in the following methods: drawRect:, layoutSubviews, viewDidLoad, viewWillAppear:. Also, loading from NIB may require quite much time.

After viewWillAppear:, iOS will make a snapshot of the new (and probably current) view to perform smooth animation between two screens. So make sure that drawing and layout code for both controller views is fast enough.

4
  • I've timed my loadView and viewDidLoad code (I'm building the view programmatically) - is this what you are referring to by drawing and layout code? Commented Oct 20, 2012 at 19:03
  • 1
    Resources are usually consumed in the following methods: drawRect:, layoutSubviews, viewDidLoad, viewWillAppear:. Also, loading from NIB may require quite much time.
    – Stream
    Commented Oct 20, 2012 at 19:06
  • I have not altered drawRect and layoutSubviews. viewDidLoad and viewWillAppear both complete before the delay that I am experiencing. My 0.7 sec is between the end of viewWillAppear and the end of viewDidAppear. Commented Oct 20, 2012 at 19:11
  • 1
    If Instruments don't help, then maybe try to make a sample “clean” app with a dumb logic and reproduce the same issue? I.e. add similar functions one-by-one until you find the bottleneck.
    – Stream
    Commented Oct 20, 2012 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.