Optimization of iOS-UITableView (original by hand) and iosuitableview

Source: Internet
Author: User

Optimization of iOS-UITableView (original by hand) and iosuitableview
TableView optimization 1: What is TableView optimization and why?

1) CPU (central processor) and GPU (graphics processor) CPUs are mainly engaged in logical computing. GPU is mainly engaged in graphics processing.

2) What CPU and GPU have in common:

All have their own cache systems, and all have their own numbers and logical computing units. They are designed to complete computing tasks.

3) differences between CPU and GPU:

The CPU core is small, but the core space is very large. It can process complicated logic.

There are many GPU cores, but each core has a relatively small space, so there is less space to process complicated logic.

For the above differences between the CPU and GPU, it is often complicated to allocate a program system to the CPU, and the operations on controls such as images are usually allocated to the GPU.

4) Results

When programmers program CPUs, they tend to use complex logical structure optimization algorithms to reduce the time Latency of computing tasks.

Programming for GPU-> use the advantage of processing massive data to increase the total data throughput to mask Latency

5) Why optimization?

Academic: balance the workload of the CPU and GPU, so as to correctly use the CPU and GPU resources, so that they can load evenly so that the FPS remains at around 60 frames, eventually, the user experience is better

Non-academic: Mastering UITableView can add extra points to the interview

Ii. How UITableView works

1) execution sequence of the tablewView proxy method

How many groups does UITableView return -----> how many lines of cells are returned in each group ---> calculate the height of each cell ----> specify the cell Layout)

2) cell Reuse

Principle: when the list is rolled (UITableView), some cells will remove the Window, but the removed cells are not immediately released. Instead, they are placed in an object pool called the reuse pool, which is in the TBD state, when a new cell appears on the Window interface, the system first looks for whether the same type of cell exists in the reuse pool, if a cell is used directly (the most intuitive manifestation is whether the new cell has opened up new memory space), if not, create a new type of cell, therefore, UITableView may have multiple types of cells, and reuse pools may also store multiple types of cells, the system defines the reuseIndentifer as the unique identifier of each cell to determine the type of cell to be reused.

Iii. Optimization of UITableView

1) use cell reuse whenever possible

Cell multiplexing can reduce memory overhead, without opening up new space, and reduce some computing workload.

2) For cells of an indefinite height, store the height of each cell into an array in advance. When a cell appears, you can directly extract the exact height from the array without temporarily calculating the height of the cell.

Text mixing and comment

Applicable to fixed cell and variable cell

3) network requests are involved in loading data (rendering) at the end of UITableView sliding to avoid freezing

1. UITableView inherits from UIScrollView and inherits the latter method.

// Sliding end Method

-(Void) scrollViewDidEndDragging :( UIScrollView *) scrollView willDecelerate :( BOOL) decelerate

// Method after the slowdown ends

-(Void) scrollViewDidEndDecelerating :( UIScrollView *) scrollView

2. if (self. tableView. dragging = NO & self. tableView. decelerating = NO) write the Data Rendering in the two methods that tableView must implement (loading the cell method) in the preceding if statement.

4) for custom controls of tableView, especially UIImageView, minimize the use of layer attributes such as rounded corners and shadows, and minimize the use of alpha (transparency) to set transparency (in project development, let the UI Designer design the source image with a rounded corner) shadow. The layer effects of the rounded corner are all completed in the GPU.

1. when multiple views overlap, the GPU performs compositing rendering, and the slowest rendering operation is hybrid. Therefore, when the view structure is too complex, a large amount of GPU resources will be consumed, therefore, when a space is not transparent, set alpha to 1 to avoid useless alpha channel synthesis and reduce GPU load.

2. Setting cornerRadius for the control and performing clip or mask operations on the control will cause offscreenrendering. This is also done in the GPU. If there are too many rounded corner objects during sliding, it will return to the high load increase of the GPU.

In this case, we can set the shouldRasterize attribute of the layer to YES. To transfer the load to the CPU, we can directly use the source image with rounded corners.

5) Try to use lazy loading

Also known as delayed loading is actually to override the getter method principle of an object: The program didn't initialize it at the beginning, but used it to open up memory for it to use.

Benefits:

1. Do not write all the code of the created object in ViewDidLoad. The code is highly readable.

2. The getter method of each control is responsible for the instantiation of each other. The code is independent of each other and is strongly loosely coupled.

6) reduce the processing logic and processing time returned to the cell.

As an example: the integration of various UI controls actually only has one control.

7) set opaque attributes for each cell-interview highlights

Opaque indicates that the result of opacity is YES or NO.

Alpha transparency

If the control is not transparent, set opaque to YES.

8) load data in Segments

Set paging loading data, that is, pull-up refresh and pull-down loading.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.