0Pricing
Swift Academy · Lesson

Optimising Hot Paths: COW, Inlining and Specialisation

Applying @inline, @_specialize and value-type optimisations based on profiler data.

Identify Before Optimising

Always profile first. Optimise only code that the Time Profiler identifies as a hot path — premature optimisation wastes time.

// Measure → Identify → Optimise → Re-measure
// A 10ms function called once is less important than
// a 0.1ms function called 10,000 times per frame

Copy-on-Write (COW)

Swift value types (Array, Dictionary) use COW: storage is shared until a mutation occurs, avoiding unnecessary copies.

var a = [1, 2, 3, 4, 5]
var b = a         // no copy yet, shared buffer
b.append(6)       // copy happens here (b mutates)
print(a.count)    // 5 — a unchanged

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