Build performance analysing in Xcode 10

Xcode 10 provides new ways to analyse your build performance. Gather valuable insights into your build performance using the new Build Timing Summary.

Build performance insights with Build Timing Summary

New in Xcode 10 is the Build with Timing Summary action. Running this action builds your project once shows a summary of the build and can be triggered in the menu using Product > Perform Action > Build with Timing Summary or using xcodebuild -buildWithTimingSummary.

Build Timing Summary Action

Build Timing Summary Action

Navigate to the Report Navigator after the build is finished and select the last build. Scroll all the way down until you see the Build Timing Summary.

Build Performance analysing using the Xcode Build Timing Summary

Xcode Build Timing Summary

This is a great starting point for investigating where you should improve your project. It’s often the CompileSwiftSources and the PhaseScriptExecution which take up most of the time. The first one obviously comes down to your Swift code. The latter points to your custom build phases. It’s often possible to disable certain run scripts which are only required for release builds.

CompileSwiftSources alone is bigger than the total tho

This indeed feels strange. I’ve asked Rick Ballard from the Xcode Build System for a clarification which gave some great insights in how the system works:

Type checking of functions and expressions

To narrow down the causes of slow build times you can enable swift-flags to gather more insights. These flags were already available before Xcode 10, but still very useful.

The compiler can warn about individual expressions that take a long time to type check using the -Xfrontend -warn-long-expression-type-checking=<limit> swift flag where <limit> can be replaced for the lower limit of the number of milliseconds that an expression must take to type check in order for the warning to be emitted.

would trigger a warning in Xcode for any function that took longer than 100ms to type-check.
The compiler will trigger a warning for any function that took longer than <limit> ms to type-check by enabling the -Xfrontend -warn-long-function-bodies=<limit> flag.

To enable these warnings, go the Build Settings, “Swift Compiler – Custom Flags”, “Other Swift Flags”:

Swift flags to analyse Build Performance

Swift flags to analyse Build Performance

Improving build performance

Although this post is focussed on analysing build performance and tons of ways are there to improve your build performance, there is own setting in Xcode which can directly improve performance.

Using Whole Module for Debug builds was a stopgap to improve builds. Whole Module prevents incremental builds.

One of them is enabling Incremental Builds instead of Whole Module compilation. Read more about it in my Enabling newly added opt-in features in Xcode 10 post.