Tips to improve Xcode Compile Time

Tram Ho

No one likes slow xcode compile like a turtle. It’s annoying to interfere with your work. However, we can still improve Xcode compile time with a few simple tricks. Let’s find out:

1) Measure your compile time correctly ⏱️

To improve your compilation time, you must first know how long your project takes to compile. To measure your compilation time, open your Terminal and enter:

After you have enabled the timer, you will see your compile time in Xcode.

Compile time in Xcode (No cleaning)

To do compile time more accurately. You should clean build folder and rebuild from scratch:

Compile time in Xcode (Already cleaned)

But if you want the most accurate compile time from Xcode, you should clean up Derived Data as well.

Compile time in Xcode (After cleaning and clearing derived data)

2) Display a warning for the slow code ⚠️

Xcode is actually quite smart and has a lot of interesting features. As Xcode can determine the code is compiling very slowly. You can enable this by adding the following lines to your Build settings in Other Swift Flag

If a function takes more than 50 milliseconds to compile, you will get a warning. (Usually you get a higher number, but I’d like to get more alerts to improve my code better)

3) Small improvement

Enable new Xcode feature from 9.2 to build concurrent tasks (concurrently).

This new feature has been released with Xcode 9.2 and Apple mentioned that it could also slow down your project as it will use more memory. To disable it, simply enter the following command in the terminal:

In case you do not want to use this new feature, disable it with the command:

4) Use let

Use let, private etc., whenever you can

After changing the var to let, my compile time decreased from about 6.5 to 6.3.

Making class final form

The final class is increasing your performance and reducing compile time.

Type inference

If we define the type for the variable, it will reduce the time the compiler knows your data type. It will reduce complie time.

5) Third party dependencies

The most common way to handle 3rd party library integration in iOS projects is to use CocoaPods. It is very simple to use but not the best option if you are interested in improving complie time.

An alternative that you can use is Carthage. It’s harder to use than CocoaPods but it will improve your complie time. Carthage achieves this by only building external dependencies when you add a new library to your project. If you add a new library, your project will not have to build all the libraries instead of the ones in Pods.

You can start to learn Carthage via the link:

6) References

Alexandros Smponias. 2019. Improve your Xcode (Swift) Compile Time – Flawless iOS – Medium. [ONLINE] Available at: . [Accessed 18 September 2019].

Improving Your Build Time in Xcode 10 · Patrick Balestra. 2019. Improving Your Build Time in Xcode 10 · Patrick Balestra. [ONLINE] Available at: . [Accessed 18 September 2019].

Share the news now

Source : Viblo