How to turn on xcode optimizations


My notes on xcode optimizations

Whole module

Whole module optimization is a compiler pass that can add significant performance gains, and so it’s always worth enabling when doing a release build of your app for the App Store. How it works is quite simple: when Swift builds the final version of your app it combines all your source files together and can evaluate the whole structure of your program at once. This lets it make extra optimizations that would be impossible before, when every file was optimized individually.

Optimization level

  • Set optimization level for debug to fastest, smallest (might want to toggle this if your not performance testing etc) Project target -> Build settings -> Optimization level

Build times:

You can enable a timer right within Xcode’s UI. This timer is not visible by default but if you run the following in the command line a time will be displayed each time you build your app.

defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES

After you have enabled the timer, you will see the time it takes to compile your app in the build status bar in Xcode.

👉 Remember to clean your xcode project to show this build time 👈

Build time details

Product → Perform Action → Build with Timing Summary option.

Terminal:

Performance regarding swift package manager tests

To test with optimization levels turned on: swift test -Xswiftc -O and type –help for other flags to use

other: