21.11 · Launch: lazy initialisation and measuring from process start
Launch time is the sum of what runs before the first frame. Part of that is decided by when Swift initialises your globals, and the clock you read decides what you think you measured.
Mental model. Know what is initialised eagerly, what lazily, and where the clock really starts.
Launch
When globals initialise, and how to measure from the true start.
- When do Swift globals and static properties initialise, and how does that move work into or out of launch?
The rules differ by where the declaration is. A global in main.swift (top-level code) runs eagerly, in order, as part of the script. A global or static stored… - How do you measure launch time from inside the app, and what can make the number wrong?
The honest start of launch is the process start time, which the kernel records. You can read it with sysctl (KERN_PROC_PID, kp_proc.p_starttime) and subtract…
More in Performance & energy
- 21.1 · Measure first: the method, the metrics and the noise
- 21.2 · Instruments templates, signposts and XCTMetric
- 21.3 · MetricKit, Organizer and a performance culture
- 21.4 · SwiftUI invalidation and long lists
- 21.5 · The costs that show up in profiles: collections, strings, formatters, JSON, images and disk
- 21.6 · Energy: CPU wake-ups, timers, radios, location and thermal state
- 21.7 · App size: thinning, on-demand resources and the binary
- 21.8 · Writing benchmarks you can believe: the optimiser, build settings and growth tests
- 21.9 · Memory you can count: allocations, dirty versus clean pages and decoded images
- 21.10 · The main thread in code: hang watchdogs, actor hops and quality of service
- 21.12 · Counting wake-ups: why polling costs energy even when the work is tiny