Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay between viewWillDisappear and viewDidDissapear

I'm seeing some performance degradation in my application after some time and I'm trying to figure out what's going exactly.

I have a complex view controller (VC1) which contains scroll view, few table views inside, some custom cells with horizontal scrolling and custom drawing etc.

After several (around 10) refreshes of all these objects (reloading tables, reposition subviews etc) when I try to call presentViewController to push another view controller above VC1 I can see about 2 seconds delay between viewWillDisappear and viewDidDissapear

I tried to profile the app to see if there are memory leaks but couldn't find any. Memory usage grows when view refreshes and switches between different modes, but then it become more or less stable in around 30m.

Works fine in Simulator, but visible slower on iPhone5. And this slowness is visible only when I try to switch from that view controller.

I ran a profiler and recorded where these 2 seconds are spent. Here is link to trace file: https://dl.dropboxusercontent.com/u/6402890/trace.trace.zip

Majority of the time spent by UIKit doing layout as I can see.

What can I do to optimize it? Is there way to take may be a snapshot of a view and use it for "leaving view" animation and restore view hierarchy when we're coming back?

UPDATE: Adding screenshot for the profiler (click for full resolution):

screenshot

UPDATE2:

After analyzing output from recursiveDescription I can see the following:

  • In the easiest case I have ~200 lines in the output. And performance is ok.
  • When I switch to more complex scenario hierarchy of views growth to ~500 lines, but still performs ok.
  • After multiple refreshes this number goes to ~2000 and this is where it become slow. Analyzing output with 2000 views I can see that ~1500 of them belong to hidden cells that are not even displayed in this mode anymore. When I'm refreshing table views cell types change too, and I'm utilizing different cells, but why the cells that are not used anymore are still being in subviews of table views?

Any recommendations?

like image 544
sha Avatar asked Jul 18 '26 14:07

sha


1 Answers

From your stack, I suspect you've added a large number of views you didn't mean to add. Since it's related to reloads, I would check your reload logic and make sure it doesn't re-add all the views in your hierarchy without removing the previous views. You can write a quick debug routine use -recursiveDescription to recursively walk the -subviews of each view and print them out to see what's in the hierarchy.

It's possible that your issue is in the layer hierarchy rather than the view hierarchy, but the symptoms you describe make me think views.


EDIT: From your update, you probably have one of two things going on. Most likely, if these are actual UITableViewCells that shouldn't even exist anymore, then you have a retain loop somewhere. Alternately, your cellForRowAtIndexPath: may be incorrect and may be adding new views to an existing cell when it should just be reconfiguring the cell.

In either case, though, 200 views seems a lot of views for a "best case." You may be overusing views in places that you should be doing custom drawing. If the performance is ok, then… ok, but I'd test carefully on your slowest supported devices.

like image 128
Rob Napier Avatar answered Jul 20 '26 03:07

Rob Napier