UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Xcode compile build times are 6.4 hours with large static swift array of structures

Forums > macOS

@bci  

I have one .swift file that holds a static array of structures that look like this:

struct ListOption: Hashable, Identifiable {
    let id: UUID = UUID()
    var name: String
    var validIfOnlyOptionSelected: Bool = false
    var data1: String = ""
    var data2: String = ""
}

let ListOptions: Array<ListOption> = [
    ListOption(name: "Code Not Found", validIfOnlyOptionSelected: true, data1: "X", data2: "99999"),
    ListOption(name: "Code1", data1: "X", data2: "54669"),
    ListOption(name: "Code2", data1: "Y", data2: "39078"),
    ListOption(name: "Code3", data1: "Z", data2: "36199"),
    ListOption(name: "Code4", data1: "X", data2: "36200"),
    ListOption(name: "Code5", data1: "Y", data2: "36191"),
    ListOption(name: "Code6", data1: "Z", data2: "36192"),
    ListOption(name: "Code7", data1: "X", data2: "36203"),
    ListOption(name: "Code8", data1: "Y", data2: "36204"),
...
]

With 350 members in the array, Xcode compiles in 4.3 seconds With it's normal 5100 members it takes 23008.7 seconds (about 6.3 hours)

Even if there were no changes to this fie.

I would rather take the hit at compile time, then have the users wait for this data to load from a local JSON file.

Anyone know of something in the Swift compiler like with ObjC and precompiled headers? Why is Xcode re-compiling this files if there were no changes to it, or the structure? Is there a better way?

Thank you for your help

4      

hi,

i have seen some compiler slowdowns on "something like this" before, but cannot give you a definitive answer as to the slowdown.

but had you considered just loading your ListOptions from the app bundle with JSON? using Paul's extension on Bundle, you could just write

let listOptions: [ListOption] = Bundle.main.decode(from: "listOptions.json")

you could compile what you have now and write your fixed data to JSON in a playground; then move it into your project. if you wanted to make changes later on, you could edit the JSON directly without recompiling.

i am curious to know if that works ... i have used a similar approach (but for slightly smaller data collections) ... and it would certainly take the Swift compiler out of the equation.

hope that helps,

DMG

4      

@bci  

@delawaremathguy - yes, I set it up this week and gave it a try. It's an extra 4 seconds at start on a 12pro., not tried it on a SE ;). The averge time they start the app, fill in the form, submit form, is about 45-90 seconds. Seems a bit long. As of now, I created 2 targets in xcode, one with only 20 ListOptions used for change/run cycle, and one with all 5100 list options for Testflight build. Thank you.

4      

@bci, the basic JSON loading uses UI thread - which means it will slow down the app.

If you were to push it to background thread with DispatchQueue.global and use high priority, I think you wouldn't notice any slowdown. Though of course having it compiled will be faster.

5      

I am looking for some good blog sites for studying. I was searching over search engines and found your blog site. Well i like your high quality blog site design plus your posting abilities. Keep doing it. Vat

4      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.