#DWURecyclingAlert
Your code usually has less than ten milliseconds to run before it causes a frame drop.1
A drop-in tool that monitors UITableViewCell & UICollectionViewCell rendering performance on the fly.
- Detects non-recycled UIView, CALayer and UIImage objects inside UITableViewCell & UICollectionViewCell.
- Displays the time it takes to render each UITableViewCell and UICollectionViewCell, in milliseconds.
#Usage Step 1: Drop DWURecyclingAlert.m into your project.
Step 2: There's no step 2.
Now launch your app, initialize a UITableView or a UICollectionView, scroll it fast and observe. Anything that are marked with an ugly bold red border are UIView or CALayer or UIImage objects that are created on the fly while the user is scrolling. You should consider caching and reusing them whenever possible.
Once you start caching them, the ugly red borders will be gone, for good. Because DWURecyclingAlert.m will intelligently detect which is cached and will only mark those that are not cached with a red border.
In addition, DWURecyclingAlert.m calculates the time your code uses to assemble each cell and presents the results in black labels at the top left corner, so that you can easily spot the heaviest ones and refactor them to free up the UI thread.
#UI Configuration
It's not unlikely that your project happens to use lots of [UIColor redColor]
here and there. Or, maybe you want to localize the millisecond warning string with your team's first language. Take a look at the UI Configuration section and customize as much as you like.
#How It Works
DWURecyclingAlert.m dynamically injects a property into every CALayer instances so that it has a way to know which is recycled and which is not.
For views that have an image property, DWURecyclingAlert.m will record and check the underlying CGImageRef values to decide whether the image is a recycled one or not.
To calculate the cell rendering time, DWURecyclingAlert.m hacks into the heart of UITableViewDataSource & UICollectionViewDataSource and injects a simple time counting logic inside each data sources' implementation of [tableView:cellForRowAtIndexPath:] & [collectionView:cellForItemAtIndexPath:]. #Disabled in Release By Default DWURecyclingAlert.m requires the DEBUG macro to compile and run. As a result, it's disabled in Release by default. If you also want to disable it in debug builds, feel free to comment out the DWURecyclingAlertEnabled macro at the top of the file. #Misc
- Whether your cells are created by code or by nib/storyboard, DWURecyclingAlert.m has a way to scan it.
- DWURecyclingAlert.m requires iOS 6 or higher to compile due to an implementation detail (NSMapTable).
#Example Project Inside this repo you can find the RecyclingAlert example project. #License DWURecyclingAlert is released under the MIT license. See LICENSE for details.
1: Facebook AsyncDisplayKit Guide. (http://asyncdisplaykit.org/guide)