Improving Drawing Performance
Drawing is a relatively expensive operation on any platform, and optimizing your drawing code should always be an important step in your development process. Table A-1 lists several tips for ensuring that your drawing code is as optimal as possible. In addition to these tips, you should always use the available performance tools to test your code and remove hotspots and redundancies.
Tip | Action |
---|---|
Draw minimally | During each update cycle, you should update only the portions of your view that actually changed. If you are using the |
Call | If you are calling Also, don’t call |
Mark opaque views as such | Compositing a view whose contents are opaque requires much less effort than compositing one that is partially transparent. To make a view opaque, the contents of the view must not contain any transparency and the |
Reuse table cells and views during scrolling | Creating new views during scrolling should be avoided at all costs. Taking the time to create new views reduces the amount of time available for updating the screen, which leads to uneven scrolling behavior. |
Reuse paths by modifying the current transformation matrix | By modifying the current transformation matrix, you can use a single path to draw content on different parts of the screen. For details, see Using Coordinate Transforms to Improve Drawing Performance. |
Avoid clearing the previous content during scrolling | By default, UIKit clears a view’s current context buffer prior to calling its |
Minimize graphics state changes while drawing | Changing the graphics state requires work by the underlying graphics subsystems. If you need to draw content that uses similar state information, try to draw that content together to reduce the number of state changes needed. |
Use Instruments to debug your performance | The Core Animation instrument can help you spot drawing performance problems in your app. In particular:
For more information, see Measuring Graphics Performance in Your iOS Device in Instruments User Guide. |
Copyright © 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-09-19