Output compile durations for swift files
You can add…
-Xfrontend -debug-time-function-bodies
…to Other Swift Flags in Swift Compiler - Custom Flags section (build settings).
Note: You have to keep same order of these flags. -Xfrontend
says that the next flag should be passed to the frontend. It will not work if you reverse the order.
Then you can get compile times in your build log:
Which is useful when you do want to optimize compile time and also it's good to attach this kind of build log when reporting an issue to Apple Swift guys about slow compile time.
Credit goes to Joe Pamer Errant compiler hacker. Currently an engineering manager at Apple (Swift, Clang), formerly at Microsoft (TypeScript, F#, JavaScript, .NET). He tweeted it as a response to Rob Rix question about profiling Swift compilation. It made me curious, so, I disassembled compiler, checked text section for more flags and found other hidden options. Don't use them in production code, just play with them.
Build time of the whole project. Run following command in terminal…
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
…restart Xcode, clean & build and…
What if I have pods?
Do same as above for your pods project
Is there a way to find out which files take a long time for Xcode to build?
Add flag -Xfrontend -debug-time-function-bodies
to your compiler.
This flag let the compiler to print out (inside report navigator) how long it takes to compile each function.
You can read more detailed instruction at,
http://irace.me/swift-profiling
How to track down slow compiling Swift code?
Use xctool. When you compile your project on the command line it will emit the time taken to compile each file to the console. e.g:
✓ Compile MySwiftFile.swift (12067 ms)
Additionally, for Swift 1.2 at least there is a flag debug-time-function
which can be passed to the Swift compiler to show you problematic functions.
Further discussion here
Project-Swift.h file after Swift 3.0 migration is compiling the same functions hundreds of times and taking 7 minutes to compile
Got the fix! Turned out to be just a settings change as detailed in this SO post here:
https://stackoverflow.com/a/40370475/1455770
This change got my compile down from 7 minutes to a far more manageable 2 minutes. Build Time Analyzer shows each file compiling only once now. I'm not 100% sure why this fixed the problem but I noticed that while generating the module-swift.h file the compiler now seems to generate it all in one go instead of file by file. This turns out to be a lot faster.
Related Topics
Session.Datataskwithurl Completionhandler Never Called
Why Does Int(Float(Int.Max)) Give Me an Error
How Are Int and String Accepted as Anyhashable
How to Open a Screen Directly in Xcuitest
Using Uiapplicationdelegateadaptor to Get Callbacks from Userdidacceptcloudkitsharewith Not Working
Swift Operator "*" Throwing Error on Two Ints
Safe to Signal Semaphore Before Deinitialization Just in Case
Disable Scrolling in Swiftui List/Form
System Volume Change Observer Not Working on iOS 15
How to Deallocate Realitykit Arview()
Why Is the Swift Compiler Marking This as an Error
How to Make a Extension for Array of Specific Type in Swift
Realitykit - How to Set a Modelentity's Transparency
How to Generate Random Numbers Without Repetition in Swift
Nsmanagedobject Changes Do Not Trigger Objectwillchange