---
title: "Profiling bites - Little Bites of Cocoa"
description: "Little Bites of Cocoa about Profiling: short tips and techniques for iOS and Mac development, each a brief explanation of one concept, technique or tool."
url: "https://littlebitesofcocoa.com/topics/44-profiling"
author: "Jake Marsh"
---
# Bites about: [Profiling](https://littlebitesofcocoa.com/topics/44-profiling)

Topics

- [Tools](https://littlebitesofcocoa.com/topics/9-tools)
- [Profiling](https://littlebitesofcocoa.com/topics/44-profiling)

## [#113: Profiling Core Animation 🏃📈](https://littlebitesofcocoa.com/113-profiling-core-animation)

 Wednesday October 28th, 2015

Topics

- [Tools](https://littlebitesofcocoa.com/topics/9-tools)
- [Profiling](https://littlebitesofcocoa.com/topics/44-profiling)

We covered how to analyze the performance of our **app** using the **Time Profiler** Instrument in [Bite #68](https://littlebitesofcocoa.com/68-time-profiler-basics), now we'll take a look at how to do the same for how quickly our **app** draws its content to the device's display. Let's get started.

First, the basics: **iOS** wants to render content to the display *60 times per second*. If our code can't keep up with that speed, some frames won't be drawn, and our **app's** UI will appear to lag and "skip" as things move around on screen. Even the slightest dip below 60 frames per second can make an **app** feel quite sluggish. One of the main places in our code this can be a challenge is when scrolling complex **table** and **collection views**. Let's look at how Instruments can help us identify and track down the cause of slow rendering **views** in our **app**:

We'll start **Profiling** like in [Bite #68](https://littlebitesofcocoa.com/68-time-profiler-basics). When *Instruments* launches, we'll select the *Core Animation Instrument* and click **Profile**. Unlike before, we'll see *two* *different* **gauges** at the top of our screen.

![Image 1 of 3 from bite #113: Profiling Core Animation](https://media.littlebitesofcocoa.com/bite-assets/113-profiling-core-animation-instrument-icon.png)

We're starting to unlock some of the power of Instruments here. The *Core Animation Instrument* measures our **app's** rendering performance *simultaneously* with our code's performance. We'll scroll our table view for a bit then find a part of the graph where we dip below 60 fps. We'll drag to select it, then select the **Time Profiler** gauge. Now we can use the techniques we learned in [Bite #68](https://littlebitesofcocoa.com/68-time-profiler-basics) to track down the offending slow **function(s)**.

![Image 2 of 3 from bite #113: Profiling Core Animation](https://media.littlebitesofcocoa.com/bite-assets/113-profiling-core-animation-debug-options-panel.png) Now the really fun stuff: We can click the ![Image 3 of 3 from bite #113: Profiling Core Animation](https://media.littlebitesofcocoa.com/bite-assets/113-profiling-core-animation-debug-options-icon.png) in the lower right-hand sidebar to show the **Debug Options** panel. These options alter how our app is drawn in *real-time* to help find problems. Here's a couple of the most helpful ones:

**Color Blended Layers** will tint views red that are being blended. Try to avoid non-opaque views or views with a clear background color.

**Color Offscreen-Rendered Yellow** will tint views that have been rendered *twice* - once on and once off-screen, yellow.

Remember, *speed is a feature*. Rendering speed is no different. Fast drawing means happy users!

Topics

- [Tools](https://littlebitesofcocoa.com/topics/9-tools)
- [Profiling](https://littlebitesofcocoa.com/topics/44-profiling)

## [#68: Time Profiler Basics 🕑📈](https://littlebitesofcocoa.com/68-time-profiler-basics)

 Wednesday August 26th, 2015

Topics

- [Tools](https://littlebitesofcocoa.com/topics/9-tools)
- [Profiling](https://littlebitesofcocoa.com/topics/44-profiling)

Measuring the performance of an app is the first step in optimizing it. Lucky for us, Apple's developer tools have *plenty* of profiling features. Let's take a look at one, **Time Profiler**. It's claim to fame is helping us fine tune performance by tracking down slow **functions**.

We start by opening our project in **Xcode**, and selecting **Product** > **Profile** from the menu.

![Image 1 of 5 from bite #68: Time Profiler Basics](https://media.littlebitesofcocoa.com/bite-assets/068-time-profiler-menu.png)   ![Image 2 of 5 from bite #68: Time Profiler Basics](https://media.littlebitesofcocoa.com/bite-assets/068-time-profiler-icon.png)

This will build our app, and launch **Instruments**. When it does, we'll select the **Time Profiler** **Instrument** and click **Profile**. Now the fun part: We click 🔴 in the top left and **Instruments** will launch our app, and begin measuring its performance. One common way to use **Time Profiler** is to discover any under-performing functions that might be bogging down our **main thread**.

![Image 3 of 5 from bite #68: Time Profiler Basics](https://media.littlebitesofcocoa.com/bite-assets/068-time-profiler-call-tree.png)

Remember, a bored **main thread** with nothing do is a happy one. Once our app is running, we'll turn on *all* the **Call Tree** options. This will clean up the data that's collected making it easier to sift through. We can flip these on and off after **profiling** to learn about different parts of the code being executed. From here we simply interact with our app, and after a few seconds we'll see data starting to appear. We expand the **Main Thread**, and see that ![Image 4 of 5 from bite #68: Time Profiler Basics](https://media.littlebitesofcocoa.com/bite-assets/068-time-profiler-data.png) a function called `insertNewObject` is at the top of the list, meaning of all the functions that were called, this one caused our **main thread** to block the most. We'll double click on it to see the *exact* spot in our code calling the sluggish **function**, ready for us to optimize:

![Image 5 of 5 from bite #68: Time Profiler Basics](https://media.littlebitesofcocoa.com/bite-assets/068-time-profiler-code.png)

 

 
