SwiftQARandom

What is Objective-C's +load method, and why does it hurt launch time?

+load is an Objective-C class method that the runtime calls automatically, once, for every class (and category) that implements it, as soon as that class’s image is loaded. That happens during launch, before main() runs. You never call it yourself.

@implementation MyClass
+ (void)load {
    // runs before main(), automatically
}
@end

Key properties

  • Eager and synchronous. It runs for every implementing class whether or not your app ever uses that class, and launch waits for it to finish. That’s why it hurts pre-main time.
  • Called once per class and per category. Categories get their own +load, and it doesn’t override the class’s — all of them run.
  • Ordering: superclasses before subclasses, classes before their categories, and a class’s dependencies’ images before it. Beyond that, order across unrelated classes isn’t something to rely on.
  • Called directly by the runtime, not through normal message dispatch, so it isn’t inherited. If a subclass doesn’t implement +load, the superclass’s isn’t called a second time for it.
  • It’s early and fragile. Other classes may not have run their own +load yet, so touching them is risky. The Swift runtime and most frameworks are up, but your app’s own setup hasn’t happened.

What people use it for

  • Method swizzling (the classic use, since it runs once and early)
  • Auto-registering things with a central registry, like plugins or routers
  • SDKs that initialize themselves without the host app calling anything

Contrast with +initialize

+initialize is called lazily, the first time the class receives a message, so it costs nothing if the class is never used. It can be called more than once (once per subclass that inherits it without overriding), so the standard guard is if (self == [MyClass class]).

Because +load is eager and +initialize is lazy, replacing a +load-based setup with +initialize — or an explicit setup call at a point you control — is the usual fix when +load shows up as a launch-time cost.

Finding offenders

+load implementations show up in a binary’s __objc_nlclslist and __objc_nlcatlist sections — “non-lazy” classes and categories are exactly the ones that implement +load. Inspecting those sections is how you enumerate every +load in a binary, including ones pulled in from third-party SDKs, without reading source.

Swift

Swift classes can’t implement +load — the compiler has disallowed it since Swift 5. You’d only hit it through Objective-C code, categories on Objective-C classes, or SDKs.

One-liner if pressed: “+load is an Objective-C hook the runtime calls for every implementing class or category at image load, before main. It’s eager, so it adds to launch time, and the fix is lazy +initialize or an explicit setup call instead.”