Swift time compilation

Swift Compiler Performance

Measure and Tools You should clean and build your project to have a better results for comparing.

  1. Xcode Build time output.
//Terminal command
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES

Output: enter image description here

  1. Build With Timing Summary.
//Xcode
Product -> Perform Action -> Build With Timing Summary

Output:

Report Navigator -> <build> -> Recent

enter image description here

  1. Type check warnings

Trigger a warning in Xcode for any function/expressions which is more than a user-defined limit to type-check

Build Settings -> Other Swift Flags(OTHER_SWIFT_FLAGS)
-Xfrontend -warn-long-function-bodies=200
-Xfrontend -warn-long-expression-type-checking=200

Output:

Instance method 'foo()' took 200ms to type-check (limit: 200ms)

enter image description here

  1. Record a time which is taken to compile every function/expression
Build Settings -> Other Swift Flags(OTHER_SWIFT_FLAGS)
-Xfrontend -debug-time-function-bodies
-Xfrontend -debug-time-expression-type-checking

Output:

Report Navigator -> <build> -> Expand All Transcripts

-Xfrontend -debug-time-function-bodies

enter image description here

-Xfrontend -debug-time-expression-type-checking

enter image description here

BuildTimeAnalyzer-for-Xcode is based on this flag. Also it has interesting column which is called Occurrences - how many times compiler is type checking it(e.g. lazy properties, closures)

enter image description here

XCLogParser analize logs

xclogparser parse --project Experiments2 --reporter html --rootOutput "/Users/User/Desktop/temp"

enter image description here

You are able to open Xcodelog with .xcactivitylog extension by changing to .zip and unzip it. After it you can open it as a text file

/Users/User/Library/Developer/Xcode/DerivedData/Experiments2-fejelsaznlrfewdtvyfyhhbgxlwl/Logs/Build/00D3B76E-B61B-4FB8-AE0B-1FAD5AF3F452.xcactivitylog

XCMetrics(by Spotify) as a next step of collecting log data

Notes:

-debug-time-compilation was removed

Experiments were made on Xcode v13.3.1. Do not forget to clean project before measure

You are able to set flag for specyfic target(e.g. in modularized project)