0Pricing
Swift Academy · Lesson

Instruments Basics: Time Profiler

Recording CPU usage, reading call trees and finding hot spots in your code.

Instruments Basics: Time Profiler is a free Swift Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Instruments?

Xcode Instruments is a performance analysis suite. Time Profiler shows you where CPU time is being spent so you can find hot spots.

// Launch: Xcode → Product → Profile (Cmd+I)
// Choose "Time Profiler" template
// Run your app and exercise the slow path

Recording a Trace

Click the record button in Instruments, exercise the feature you want to profile, then stop recording.

// 1. Connect device or use simulator
// 2. Launch with Profile (Cmd+I)
// 3. Select Time Profiler
// 4. Record for 5-30 seconds
// 5. Stop and analyze

Call Tree View

The Call Tree shows functions by CPU time consumed. The heaviest call paths appear at the top of the hierarchy.

// Call Tree columns:
// Self %: time spent in this function exclusively
// Symbol Name: function or method name
// Expand to see callers/callees

Heaviest Stack Trace

The Heaviest Stack Trace panel shows the single most sampled call path — often the best place to start optimizing.

// In Time Profiler:
// View → Heaviest Stack Trace
// Pinpoints the exact line consuming the most CPU

Filtering Samples

Enable "Hide System Libraries" and "Invert Call Tree" to focus on your own code rather than Apple frameworks.

// Call Tree options (bottom of Instruments):
// ☑ Invert Call Tree    – shows leaf functions first
// ☑ Hide System Libraries – filters out OS internals

Navigating to Source

Double-click a symbol in the call tree to jump directly to the offending line in Xcode.

// Double-click → opens file in Xcode at the hot line
// Red/orange annotation shows time spent per line

Time Profiler + SwiftUI

In SwiftUI apps, look for unexpected calls to body — excessive redraws show up as repeated View.body entries in the call tree.

// Common SwiftUI hot spots:
// - body called 100+ times per second
// - Equatable not implemented, causing unnecessary diffs
// - Heavy computation in body instead of a model

Inspecting Main Thread vs Background

The thread lane at the top shows activity per thread. CPU spikes on background threads may indicate excessive work off the main thread.

// Thread lanes: Main Thread, Thread 2, Thread 3...
// Select a thread to see its call tree in isolation

Time Profiler for Startup

Measure app launch time by profiling from launch and looking at the first seconds of the trace.

// Instruments → File → Launch Profile
// Measures time from process start to first frame render

Setting a Baseline

Record a baseline trace before optimizing. After changes, re-profile and compare to confirm improvement.

// Baseline: 45ms for imageLoad()
// After optimization: 8ms for imageLoad()
// Confirm: 5.6x speedup verified in Instruments

Tips for Accurate Profiling

Profile on a physical device in Release build. Simulators and Debug builds skew performance measurements.

// Always:
// 1. Use physical device
// 2. Build with Release configuration (Product → Scheme → Edit → Build → Release)
// 3. Repeat measurement 3+ times for consistency

Quick Check

Which Instruments call tree option shows the leaf (most time-consuming) functions at the top of the list?

Lesson Recap

Profile with Cmd+I → Time Profiler. Use Invert Call Tree + Hide System Libraries to see your code first. Double-click symbols to navigate to source. Profile on device in Release mode. Establish baselines before and after optimizations to confirm improvement.

Frequently asked questions

Is the “Instruments Basics: Time Profiler” lesson free?

Yes — the full text of “Instruments Basics: Time Profiler” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Instruments Basics: Time Profiler”?

Recording CPU usage, reading call trees and finding hot spots in your code. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Instruments Basics: Time Profiler” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Instruments Basics: Time Profiler
  2. Allocations and Leaks Instruments
  3. Main Thread Checker and Hangs
  4. Optimising Hot Paths: COW, Inlining and Specialisation
← Back to Swift Academy