1: What is a good performance optimization scheme for tableView?
CPU (Central Processing Unit, Object creation and destruction, object property adjustment, layout calculation, text calculation and typesetting, image format conversion and decoding, image drawing (Core Graphics) Graphics Processing Unit (GPU) Graphics processor (GPU) texture rendering is a double-buffering mechanism in iOS, and there is a lag in the pre-frame cache and post-frame cache. The reason for this is that the CPU or GPU takes too long time, resulting in the incomplete CPU calculation or GPU rendering when the vertical signal comes, thus dropping the frame.
The main idea of Catton’s solution
(1) reduce CPU and GPU resource consumption as much as possible. (2) according to the brush frame rate of 60FPS, VSync signal will be sent every 16ms
1.3 Reducing the CPU Load
1.3.1 Calculate the height of the cell in advance and cache it in the corresponding data source model. 1.3.2 Minimize storyboards and xiBs. 1.3.3 Minimize layout during sliding
1.4 Load on demand
// Load on demand – If the target row differs from the current row by more than the specified number of rows, only specify 3 rows before and after the target scroll range to load.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
1.5 Asynchronous Drawing
When the view hierarchy is large, it can be drawn asynchronously, using UIGraphics to draw the content and then generate an image for presentation. 1.5.1 Processing data Sources 1.5.2 Asynchronously Drawing Data
1.6 Delay loading images
Listen for the state of the runloop and draw loaded images every time it is about to sleep, i.e. in the kCFRunLoopBeforeWaiting state
2. How do you deal with interface lag and detection?
What are the causes of page lag? 1. Deadlock: the main thread takes lock A and needs to acquire lock B, while the child thread takes lock B and needs to lock A, then the main thread waits for lock B to be released, and the child thread waits for lock A to be released. Lock grab: The main thread needs to access the DB and a child thread inserts data into the DB. The main thread has a large amount of IO: the main thread writes a large amount of data directly in order to facilitate the page to be blocked. Main thread large amount of calculation: the algorithm in the program is not reasonable, a large number of loops and other operations, resulting in the main thread a function to occupy a large amount of CPU. 5. Lots of UI drawing: Complex UI, text and text mixing, etc., bring lots of UI drawing.
How to locate the Caton problem?
1. Deadlocks are usually accompanied by Crash, which can be analyzed through Crash logs. The lock grab problem is not easy to solve, we can print the lock wait time, but we also need to know who is holding the lock, we can detect the execution of Runloop, observe the time. 3. A lot of I/O can be timed at the start and end of a function to log the time occupied by the function. 4. 5. A large amount of UI drawing is generally unavoidable, as there will always be complex page drawing in APP. We can use AsnycDisplayKit and other frameworks for pre-typesetting, asynchronous drawing and picture decoding.
If we can capture the stack information of the thread at the time of the above problem, we can quickly locate the problem and solve it. So, the idea behind iOS stacken checks is to create a child thread to monitor the execution of the main Runloop, see if the execution time exceeds the pre-threshold, and log the thread stack immediately if it does.
How can I tell if the main thread has stalled?
FPS reduces CPU usage high mainline Runloop execution takes a long time
FPS is compatible with the latter two features, but in actual operation, IT is found that FPS is not good for measuring jitter. In the case of lock snatching or a large amount of IO, it is not possible to rely on the CPU alone, so it is generally detected that if the CPU usage exceeds 100%, the main thread Runloop execution is sufficient to exceed the threshold.
3: What is your understanding of off-screen rendering?
What is off-screen rendering
Off-screen Rendering refers to off-screen Rendering, when the GPU creates a new buffer in addition to the current Screen buffer to render
Why do I need to render off-screen
Because rendering a view to the screen in the frame buffer is discarded. So when we have multiple sets of views that need to be combined and then processed uniformly. You need to create an additional off-screen buffer in the screen buffer to record these views. Then unified processing. Finally rendering display
When does an off-screen rendering happen?
1. Round the corner after adding the picture 2. Round the corner after adding the background color and picture 2. Rasterize 4. Set the opacity of the combined view 5. Shadow 6. System ground glass effect
###### How to avoid off-screen rendering? 1. Off-screen rendering for rounded corners. We can adopt four solutions: a. Cover it with a hollow view with rounded corners B. Use the rounded corner method in YYImage C. Use CALayer with UIBezierPath 2. If the view cannot be reused. It is not static. It is not recommended to enable rasterization when frequent modifications are required. Because this will turn on the off-screen rendering and affect efficiency 3. Use transparency as little as possible or not 4. Draw asynchronously. Reduce layers
4: How to reduce the size of APP package
There are two ways to reduce package size
A. Executable file
Strip Linked Product, Make Strings read-only, Symbols Hidden by Default set to YES Enable C++ Exceptions, Enable objective-C Exceptions set to NO, Other C Flags add -fno-exceptions to detect unused code with AppCode: Menu bar -> Code -> Inspect Code writes LLVM plug-in that detects duplicate Code, uncalled Code
Resources.
Resources including pictures, audio, video and other optimized ways can be lossless compression of resources to remove unused resources
5. How to check for memory leaks?
A. Leaks dynamic detection project run – product-profile-instrums-leaks b.Analyze static analysis of product-profile-analyze c This section describes how to solve memory leaks caused by C language in oc. Use MLeaksFinder- Accurate iOS memory leak detection tool
6. What aspects should be optimized for APP startup time?
App startup Process iOS app startup can be divided into pre-main stage and main() stage. Pre-main stage refers to the operation performed before the main function, and main stage refers to the stage of displaying the main function to the home page. Where the system does the following:
premain
Load all dependent mach-O files (recursively call mach-O loading method) load dynamic link library loader dyLD (Dynamic loader) locate internal and external pointer references, C++ static object loads and calls ObjC’s +load function to execute C functions declared as attribute(((constructor))
main
Call the main () calls UIApplicationMain applicationWillFinishLaunching () call The usual premain phase optimizations are to eliminate useless class methods, reduce +load operations, reduce attribute((((()) C functions, and reduce the number of dynamic libraries that start loading. The optimization of the main stage is to delay the non-necessary operations at the start of the loading, statistics and optimization of the time-consuming method after the display of the home page. For some operations that can be placed in the sub-thread, it can try not to occupy the main thread.