Xcode 8 very slow Swift compilation

Since Swift 3 and Xcode 8, my project has been compiling quite slowly. Each time I add an empty line to the file, recompilation takes a whole minute. When I check the output, there is no specific file that takes a very long time. (I also used this measurement tool: https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode )

It always turns out to compile 4 files at a time. The rhythm is pretty steady. Just really slow ...

In addition: whenever I open files or switch between them, the process of autofilling or the appearance of errors / warnings can take a very long time.

What things can I check? I almost feel that there is some kind of flag that I set that just slows down the build speed like crazy.

EDIT: This is not a solution to the main problem, but I spent some time migrating more code to wireframes. It mattered (simply because fewer files had to be recompiled each time). This should not be necessary, but it has become unbearable ... Of course, I am still very looking for the right solution.

+36
ios xcode swift swift3 xcode8
Oct 05 '16 at 17:09
source share
8 answers

The problem with this problem is that we do not know where the initialization / declaration is incorrect. The solution that my colleague offers is to find which function takes a lot of time to compile like this:

  • Go to Project choose a goal
  • Build Settings β†’ Swift Compiler - Custom Flags
  • Add to Other Swift Flags -Xfrontend -warn-long-function-bodies=50 (50 represents time in milliseconds)

After this, the following warning should appear:

Getter 'frameDescription' took 108 ms to type check (limit: 50 ms)

and after that you know what to do;)

+26
Jan 22 '17 at 21:25
source share

I had the same problem only since upgrading to Swift 3 / XCode 8, and it seems to be caused by large array literals similar to these .

I managed to fix the problem by adding type annotations to variables assigned to an array literal, for example.

 let array: Array<String> = ["1", "2", "3", "4", "5", "6", "7", "8"] 

instead

 let array = ["1", "2", "3", "4", "5", "6", "7", "8"] 
+5
Oct 13 '16 at 22:03
source share

This is a problem with Xcode 8, where it does not perform incremental builds correctly. If you are editing one quick file, it should only compile this file. This has already been said here: Xcode 8 completely rebuilds the project

4 files at a time are built in the way that Xcode performs a complete rebuild of the project, which should not be repeated if you only changed one line in one file.

+5
Oct 17 '16 at 18:21
source share

In my case, I used a helper function to save some data in Firebase. This function returned a dictionary with about 20 elements, and it took about 40 minutes to compile. My solution was to initialize an empty dictionary and then add items one by one before someDict . Now it compiles in less than 30 seconds. Hope this helps.

Before

 func toAnyObject() -> AnyObject { return ["BookingAmount":BookingAmount, "BookingNumber":BookingNumber, "PostCode":PostCode, "SelectedBathRow":SelectedBathRow, "SelectedBedRow":SelectedBedRow, "DateAndTime":DateAndTime, "TimeStampDateAndTime":TimeStampDateAndTime, "TimeStampBookingSavedInDB": TimeStampBookingSavedInDB, "FrequencyName":FrequencyName, "FrequecyAmount":FrequecyAmount, "insideCabinets": insideCabinets, "insideFridge": insideFridge, "insideOven": insideOven, "laundryWash": laundryWash, "interiorWindows": interiorWindows, "FullName":FullName, "SuppliesName":SuppliesName, "SuppliesAmount":SuppliesAmount, "FlatNumber":FlatNumber, "StreetAddress":StreetAddress, "PhoneNumber":PhoneNumber, "EmailAddress":EmailAddress] as AnyObject } 

After

  func toAnyObject() -> AnyObject { var someDict = [String : AnyObject]() someDict["BookingAmount"] = self.BookingAmount as AnyObject? someDict["BookingNumber"] = self.BookingNumber as AnyObject? someDict["PostCode"] = self.PostCode as AnyObject? someDict["SelectedBathRow"] = self.SelectedBathRow as AnyObject? someDict["SelectedBedRow"] = self.SelectedBedRow as AnyObject? someDict["DateAndTime"] = self.DateAndTime as AnyObject? someDict["TimeStampDateAndTime"] = self.TimeStampDateAndTime as AnyObject? someDict["TimeStampBookingSavedInDB"] = self.TimeStampBookingSavedInDB as AnyObject? someDict["FrequencyName"] = self.FrequencyName as AnyObject? someDict["FrequecyAmount"] = self.FrequecyAmount as AnyObject? someDict["insideCabinets"] = self.insideCabinets as AnyObject? someDict["insideFridge"] = self.insideFridge as AnyObject? someDict["insideOven"] = self.insideOven as AnyObject? someDict["laundryWash"] = self.laundryWash as AnyObject? someDict["interiorWindows"] = self.interiorWindows as AnyObject? someDict["FullName"] = self.FullName as AnyObject? someDict["SuppliesName"] = self.SuppliesName as AnyObject? someDict["SuppliesAmount"] = self.SuppliesAmount as AnyObject? someDict["FlatNumber"] = self.FlatNumber as AnyObject? someDict["StreetAddress"] = self.StreetAddress as AnyObject? someDict["PhoneNumber"] = self.PhoneNumber as AnyObject? someDict["EmailAddress"] = self.EmailAddress as AnyObject? return someDict as AnyObject } 
+3
Dec 31 '16 at 1:45
source share

This worked for me on one of my projects.

Go to Product β†’ Scheme β†’ Edit Scheme. Select "Build" on the left and uncheck the box "Find implicit dependencies." But this flag should remain checked when you build a project for the first time.

Source

It was a simple project, and he increased one of my buildings from 1 minute to 2 seconds.

On a physical device, I got these results. For one of my large projects (42 files) it only decreased from 2:36 to 2:20. Then I added: SWIFT_WHOLE_MODULE_OPTIMIZATION = YES to create the settings as a user setting. Time reached - 2:00

In the simulator, the assembly was 49 seconds the first time I used.

Go to Product β†’ Scheme β†’ Edit Scheme. Select "Build" on the left and uncheck the box "Find implicit dependencies." But this flag should remain checked when you build a project for the first time.

and the assembly took 7 seconds.

Hope this helps.

+1
Jan 24 '17 at 3:41 on
source share

I was able to significantly reduce the time it takes to quickly compile the project, avoiding the use of the Nil-Coalescing operator and string concatenation.

In other words, where I had something like:

 let x = "one" + object.nullableProperty ?? "" 

I changed it to

 let x = String(format: "one %@", object.nullableProperty ?? "") 

My compilation time has been drastically reduced - from 20 minutes to 20 seconds.

+1
Apr 11 '17 at 19:31 on
source share

Make sure you are not combining arrays like let combinedArrays = array1 + array2 . There's also a known bug for type inference here, where Swift takes the time to figure out which type should be combinedArrays . Instead, [array1, array2].joined() should work just as well and compile much faster.

0
Oct 17 '16 at 18:08
source share

One common practice that slows down compilation time is to use Array.append and String.append (or their equivalents to the + operator). For String s, it's better to use a formatted string, so instead of

 let hello = "Hello, " let world = "World!" let combinedString = hello + world 

you should use

 let combinedString = "\(hello)\(world)" 

I do not remember the exact acceleration, but for these lines it was about 10 times. Most likely, it is likely that this will not have noticeable acceleration for any, but the smallest projects. For example, in our project there are hundreds of Swift files, as well as many Objective-C, and the compilation time is often 10 minutes or more, sometimes even when the only change was a file without Swift.

0
Oct 17 '16 at 18:11
source share



All Articles