Friday, August 4, 2017

Using Static Frameworks to Speed Up Launching

Eric Horacek (via Ljuba Miljkovic):

This slowdown happens because every dynamic framework adds overhead for dyld to do before an app’s main() function is called (known as “loading, rebasing, and binding”). In this WWDC 2016 talk, Apple suggests replacing dynamic frameworks with static archives to mitigate this. To take this approach, we rebuilt as many of our dynamic frameworks as possible statically and then merged them into a single monolithic dynamic framework named AutomaticCore.

[…]

Apple wasn’t exaggerating when they said too many dynamic frameworks could slow down your app’s launch time. However, merging our dynamic frameworks wasn’t trivial: we had to rework our development workflow to build our app this way from now on.

[…]

It was not trivial to add support to Carthage for building static archives (.a files). However, with some minimal changes, we were able to update Carthage to support building static frameworks (.framework files). Static frameworks are just like static archives, but packaged differently. They have a similar structure to dynamic frameworks, but with a static Mach-O file in place of a dynamic one.

[…]

However, unlike dynamic frameworks, static frameworks are not embedded—meaning we needed to do some extra legwork to make their resources available.

See also: App Startup Time: Past, Present, and Future.

4 Comments RSS · Twitter

Is it still useful in High Sierra ? Now that binaries are preprocessed once to compute all the stuff that make them slow to start head of time, it shouldn't make a big difference if you use static instead of dynamic frameworks.

@Jean-Daniel I haven’t watched the linked WWDC session yet, but I think I heard that only system apps get the full benefit under High Sierra.

in the video, they said all apps benefit from it. System apps are preprocessed at installation time, and start fast at the first launch, other apps are preprocessed at first launch, but after that they use the fast path too. And on iPhone they are all preprocessed at install time.

@Jean-Daniel Great—thanks for explaining that.

Leave a Comment