Summary of iOS performance optimizations

Source: Internet
Author: User

iOS Performance optimization analysis

First, be familiar with a few concepts

    1. What is the difference between PNG and JPG?
      Images in PNG format have alpha channels and JPEG does not. PNG lossless compression, JPEG allows you to choose the compression quality of 0-100%. If an alpha channel (transparent) is required, it can only be in PNG format.
    2. CPU and GPU

    3. If you want to see the difference between the two, first understand the hierarchical structure behind the iOS view the bottom line is the hardware layer, which consists of the GPU and CPU. What we often say about hardware acceleration is the fact that Opengl,core Animation/uikit is based on the GPU's implementation of computer graphics compositing and drawing, and so far the hardware acceleration on iOS is still significantly ahead of Android, which relies on CPU drawing, The vast majority of animation implementations will make people feel obvious lag.

iOS View rendering architecture and rationale

    1. Many of the underlying behaviors of the UIView class depend heavily on the other 2. Object. Uikit There is a coreanimation layer object behind each view object, which is an instance of the Calayer class that provides basic support for rendering, layout, compositing, and animation of the view content
    2. Unlike Mac OS, iOS integrates coreanimation into the core of the view rendering implementation. Since Uikit provides a transparent interface in the SDK, developers do not have to care and direct access to coreanimation in most cases. However, if you want to achieve particularly complex rendering and animation, you need to use the interface to Coreanimation to support the
    3. Coreanimation's basic coreanimation leverages hardware acceleration and architectural optimizations for fast rendering and real-time animation. When the DrawRect method of a view is called for the first time, the layer snaps the result of the depiction into a bitmap and uses the bitmap whenever possible for subsequent redrawing to avoid too much overhead. Coreanimation stores the layers associated with the View object in the hierarchy of the layer tree. You can add special layers to the layer tree to achieve different effects. Layer objects are the driving force behind the iOS rendering and layout system, and most view properties are actually a thin package of their layer object properties. Represents the tree: the current state of the layer when it is presented to the user. Render tree: Run on a separate thread, without affecting the main thread of the app, for animated rendering.

How to optimize the view load speed

Off-screen drawing (offscreen drawing)

Off-screen drawing (offscreen drawing) refers to the GPU while drawing on the current screen, while the other side of the screen has not processed the image information through the CPU to generate image information processing in iOS, off-screen drawing in the following cases will automatically trigger:

1.Core Graphics (any class that starts with CG) 2. In the DrawRect method, even the empty method implements 3. All Shouldrasterize properties are Calayers object 4 for Yes.  All used Masks ( Setmaskstobounds) and Dynamic Shadow (setshadow*) Calayers objects 5. All text is drawn, including Coretext6.group opacity (uiviewgroupopacity)


Accelerated image display for iOS devices with pre-rendering

When the image is displayed, decompression and resampling consume a lot of CPU time, and if you pre-draw an image in a bitmap context and then cache the image, you can save the heavy work. For this reason, there are cute people who did the experiment.

Can look at concrete examples of the experiment in http://mobile.51cto.com/iphone-279459.htm



Reference Address: Http://www.taofengping.com/2013/05/17/designing-for-ios-graphics-performance/#.U4l3eFFvB50

                    http://mobile.51cto.com/ Iphone-279459.htm

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.