This article mainly discusses IOS project optimization from the following seven directions
1.CUP performance optimization
CUP is mainly responsible for object creation and destruction, layout calculation, text calculation and typesetting, picture decoding, image drawing, etc
We can optimize CUP as follows
1.1 Try to use lightweight objects, such as CALayer instead of UIView where event handling is not needed
1.2 Do not frequently call UIView properties and minimize unnecessary modifications
1.3 Try to calculate the layout in advance and store it in memory to avoid repeated calculation
1.4 Manually setting the frame itself consumes less resources than Autolayout
1.5 The image size should be exactly the same as the UIImageView size to avoid scaling algorithms
1.6 Try to put time-consuming operations into sub-threads (such as text size calculation, drawing, picture decoding and drawing, etc.)
In the reference YYKitDemo WBStatusTimelineViewController
2.GUP performance optimization
GPU is mainly responsible for rendering textures. For GPU, we can do the following optimization:
2.1 Combine as many pictures as possible into one for display
2.2 Minimize the number and layers of views. The more views and layers there are, the more layers need to be rendered
2.3 Reduce the transparency of the view, especially the upper view, which will lead to mixed calculation of pixels
2.4 Try to avoid off-screen rendering. If you want to know about off-screen rendering, you can go to my other article juejin.cn/post/700586…
3. Memory optimization
3.1 We can statically Analyze our code through the Analyze of Xcode, detect unused variables and some syntax errors, etc
3.2 We can dynamically detect memory Leaks by using Xcode -open Developer Tool-Instruments-Leaks
4. Caton optimization
4.1 We can use Runloop to detect project lag. Welcome to add other methods. You can refer to github.com/search?q=LX…
5. Optimization of power consumption
5.1 Use timers less
5.2 Use the database if the data volume is large
5.3 Reducing Compressed Network Data
5.4 Replace frequent network requests with appropriate caching
5.5 If real-time positioning is not required, turn it off in time after positioning
5.6 Resumable Data Transfer on a Breakpoint
6.APP startup optimization, mainly for cold startup optimization
(Edit Scheme -> Run -> Arguments) There are three stages of cold startup: 1.dyld 2.runtime 3.main
Dyld :Apple dynamic linker that can be used to install mach-0 files
Optimization:
Reduce dynamic libraries and merge some of them
Reduce the number of Objc classes, classes, reduce the number of selectors, and periodically clean up unused classes, classes
Reduce the number of C++ virtual functions
Swift tries to use structs instead of classes
6.1.2 the runtime:
Map_images is called for parsing and processing of executable file contents
Call call_load_methods in load_images and call the +load method for all classes and categories
Initialize various objC structures (register objC classes, initialize class objects, etc.)
A function modified by a C++ static initializer and _attribute_((constructor))
So far, the executable files and dynamic library of all the symbols () Class, Protocol, the Selector, IMP… All have been successfully loaded into memory in the format managed by the Runtime
Optimization: use +initialize+ singleton instead of +load
6.1.3 Calling main
Optimization: Delay as many actions as possible without affecting the user experience, not all in the finishLaunching
6.1.4 Binary Rearrangement Recommended articles: juejin.cn/post/684490…
7. The APP
7.1 Lossless compression of image resources
7.2 Removing unused resources: github.com/tinymind/LS… Github.com/netyouli/WH…
7.3 Checking Unused code: github.com/netyouli/WH…