iOS app startup time optimization


This is a summary note of WWDC 2016 talk “Optimizing App Startup Time” by Dyld Architect Nick Kledzik and Dyld Visionary Louis Gerbarg. It’s an overwhelming talk with a lot of low-level programming terminologies but it’s a great talk so you should watch it.

File Types

  • Executable — Main binary for application
  • Dylib — Dynamic library (aka DSO or DLL)
  • Bundle — Dylib that cannot be linked, only dlopen(), e.g. plug-ins
  • Image — An executable, dylib, or bundle
  • Framework — Dylib with directory for resources and headers

ASLR

  • Address Space Layout Randomization
  • Images load at random address

Code Signing

  • Content of each page is hashed
  • Hash is verified on page-in

Debugging launch time – DYLD_PRINT_STATISTICS

Drawing

TL;DR – Improve launch time

  1. Dylib loading time
    • Use fewer dylibs
      • Merge dylibs
      • Use static archives
  2. Rebase/binding time
    • Use Swift structs
    • Reduce
      • Obj-C metadata
      • __DATA pointers
      • c++ virtual
  3. Initializers
    • Replace Obj-C +load with +initialize
    • Use Swift
    • Do not call dlopen() in initializers
    • Do not create threads in initializers