I have a data structure in my Xcode project similar to this:
struct Group: {
let name: String
var items: [Thing]
}
struct Thing: {
let description: String
let variants: [Thing]?
}
var data: [Group] =
[Group(name: "Group 1",
items: [Thing(description: "Thing 1", variants: nil),
Thing(description: "Thing 2", variants: nil),
... ]),
Group(name: "Group 2",
items: [Thing(description: "AnotherThing 1", variants: [Thing(description: "Variant Thing1)",
Thing(description: "Variant Thing2)",
... ]),
Thing(description: "AnotherThing 2", variants: [Thing(description: "Variant Thing 101"),
Thing(description: "Variant Thing 102"),
... ]),
... ])]
In total there are about 10 Group’s containing about 3200 Thing’s; the Thing’s are spread about equally in "items" arrays and "variants" arrays.
Xcode takes from 3 to 5 minutes to compile this one file. What can I do to reduce this to a reasonable time?
Aside: In addition to being slow to compile, this data structure is making the Xcode profiler go bonkers. Fairly often, the profiler will eat up all of the swap space and crash the machine.
2
Answers
I didn't do it exactly like matt suggested but his advice put me onto a way to do it and not be too ugly.
This got the compile time down from 3-5 minutes to 30 seconds. I can live with that. I could probably get it down further by breaking out the "variants" arrays.
Try changing the assignment to
In my experience, these slowdowns are mostly due to type inference, and specifying the type explicitly helps a lot.
If that doesn’t work, follow the advice given by Joakim Danielson.