IOS * Cell Performance: Autolayout vs Frame?

I use Auto-layout for cells (UITableViewCell and UICollectionViewCell), but have noticed a significant performance penalty when cells are reused, and I wonder what I can do to improve it.

Perhaps this is due to the way I create / configure a cell, in my application I need to show books as cells, and different genres of books have different layouts, but I only have one BookCell, I reconfigure the restrictions when a cell is created / reused for specific book based on the genre of the book.

In my opinion, in my case, the automatic layout should be slower than the fixed frame, since the following steps:

auto layout

  • remove current restrictions
  • add additional restrictions depending on the genre of the book
  • set all tags / images for the book

I think that internally in step 2 iOS will restart the constraint resolver, and in step 3 the constraints will be re-configured (i.e. re-run the solver) to satisfy all labels and images with typing and images.

fixed layout

(there is a list of different frames for labels, images, for different genres) 1. reinstall all labels, image frames 2. Set image labels and image images

I need some time to convert all the cells of the automatic layout to use fixed frames, and about what I can come up with to improve performance:

  • duplicate the common BookCell and create one cell for each genre.
  • set all tags, images, up .
  • Not too sure about this, should I add auto-package restrictions to the updateConstraints method or to the initializer (for example, initWithTableViewCellStyle:reusableIdentifier: ?

Thank you so much!

+7
ios objective-c uitableview autolayout uicollectionview
source share
2 answers

Converting from an automatic layout to a frame will be time consuming and give you the least performance advantage. Not to mention the complications when you develop in iOS7. (See my other answer to this here).

As Kuglerโ€™s research shows, automatic layout should be fast enough. Do not forget the frames or the automatic layout, it all comes down to mathematical calculations, something modern processors are pretty good.

In your case, I would recommend a completely different approach. To get started, make sure that you are managing constraints in the right place. This means updateConstraints and updatedViewConstraints . Adding or removing restrictions is an expensive operation. But in fact, you should only do this once - using these methods - when creating a view. Be sure to check that restrictions are already in place so that you do not receive exceptions by adding multiple times.

Also, remember that you do not need to add or remove constraints if you are just updating constant . Something you can do outside of the above methods.

Next, consider what happens to the table view. It scrolls quickly, and cellForRowAtIndexPath requests the next cell. In your case, all cameras look very different. To solve this problem, use a different reuseIdentifier for each option.

While working with data to fill the cell is minimal, you can see a tiny tremor when creating the initial cell. However, after that the scrolling should be very smooth.

+4
source share

From my understanding, in my case, the car should be slower than a fixed frame

Car sales are almost always slower. But in most situations, the difference between using an automatic layout and a fixed layout should not be noticeable.

If you have only five different genres, itโ€™s great to use different unique cell reuse identifiers for each genre / layout. This eliminates the need to add / remove restrictions after each detection operation. See this excellent answer for more information: https://stackoverflow.com/a/166269/

+2
source share

All Articles