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.

  1. When do Swift globals and static properties initialise, and how does that move work into or out of launch? 21.11.1 · L3
    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…
  2. How do you measure launch time from inside the app, and what can make the number wrong? 21.11.2 · L5
    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