This article introduces TableView optimization, the most contact in the project is TableView, if your project show data is more complex, cell content is more, TableView optimization is particularly important, especially level one page and level two pages. This article focuses on the effects of optimization from a code and demo point of view.
1. Entry level
-
Reuse, proper use of reuseIdentifier
-
Try to set the background color of the views to opaque, transparent will have layer mixing, increase GPU calculation
Often forget to set the uilabel. BackgroundColor (set the colors much like the parent view), don’t be [[UIColor grayColor] colorWithAlphaComponent: 0.2 f], not transparent, if there is a Chinese uilable, MasksToBounds = YES. MasksToBounds = YES
-
Avoid xiBs that are too large.
XIB is first encoded into PLIST or XML and stored in disk. It takes time to load XIB files. If there is a large picture inside the home page, it will seriously affect the program startup time. You can use link-map to analyze the details.
- Do not block the main thread UIKit. This library is a big bug for Apple. If the page loads a lot of resources, use YYkit
- Ensure the size of the image size and ImageViews always, don’t cut, more not UIImageJPEGRepresentation pictures decoding of SAO operation
1. Array: Fast index query, slow key query, slow insert/delete 2. Dictionary/key query, fast set/value query, fast insert/delete 7. Gzip compression, text compression is very significant, with little.
2. The intermediate
-
Reuse and lazy load Views
- Reuse is a reuse control - lazy loading: 1. Better reading 2. Viewdidload will only be executed once, not initialized multiple times.Copy the code
-
Cache
- Caches are unlikely to change but need to be read frequently, the most typical is the home page, use your imagination. - Response, image, and calculation result of the remote server - NSCache is similar to NSDictionary except that when the system reclaims memory, NSCache automatically deletes its contents.Copy the code
3. Handle memory warnings and remove strong references for caches, image objects and other objects that can be recreated.
Self-brain, how to demonstrate, how to monitor, look up relevant informationCopy the code
4. Reuse large overhead objects
5. Some objects are slow to initialize
Such as NSCalendar NSDateFormatter (including the formatter. DateFormat = @ “yyyy – MM – dd – HH – MM – ss” enumerated), can use the singleton to create
- Avoid reprocessing data and use the same data structure on the server and client.
7. Choosing the right data format to parse JSON can be faster than XML, but XML has the advantage that you don’t have to wait until the entire document has been downloaded to parse as json does. When you’re dealing with large amounts of data, you can dramatically reduce memory consumption, increase performance, and increase the user experience.
8. Set the background image correctly
- Full screen background image, using UIImageView - Small background image, such as navigation bar, avatar, etc., using '[UIColor colorWithPatternImage:<#(nonNULL UIImage *)#>]'Copy the code
- Shadowpath. preferably use CAShapeLayer instead of CALayer, hardware accelerated, set shadows
10. The cache line is high and the data volume is small
11. Reduce the number of subviews
- Can reduce layout between views - can reduce layer blendingCopy the code
3 senior
- Accelerate the start time after the start of the load page, do not load tasks on the main thread, huge XIB, SB file parsing operations
- Use AutoreleasePool torelease objects that create many temporary objects
- IOS Performance Optimization (Middle)
4. High performance rounded corners. If the number of rounded corners on a page is less than 25, optimization 5 is not considered. Where interaction (gestures, event responses, etc.) is not required, consider using CALayer instead of UIView.6. Controls the maximum number of concurrent threads. Too many concurrent threads consume too much memory. 7. Text processing (calculation, drawing) picture processing (decoding, drawing) and other sub-threads
4 Cell reuse problem using NStimer
Solution: TableView countdown control reuse problem solution
Reference article:
- UITableView Performance Optimization – Intermediate
- List Fluency Optimization for iOS Performance Optimization
- TableView countdown control reuse problem solution
, etc.