Why compile an array size 3773 statically init each element very slow?

It's best to continue here to not mix the threads.

I confirm there's something odd going on here. Xcode consuming all those 10s or even 100s of GB and then crashing my computer (it did) is not good. I tried 4K of your lines with different permutations of explicit types vs ".init":

let emojis: [Emoji] = [
    .init(character: "😀", name: "Grinning face", category: .init(group: "Smileys & Emotion", subgroup: "face-smiling"), isNew: false, zwjGroup: nil),
// 4K of those
]

vs

let emojis: [Emoji] = [
    Emoji(character: "😀", name: "Grinning face", category: .init(group: "Smileys & Emotion", subgroup: "face-smiling"), isNew: false, zwjGroup: nil),
// 4K of those
]

vs

let emojis: [Emoji] = [
    .init(character: "😀", name: "Grinning face", category: Category(group: "Smileys & Emotion", subgroup: "face-smiling"), isNew: false, zwjGroup: nil),
// 4K of those
]

vs

let emojis: [Emoji] = [
    Emoji(character: "😀", name: "Grinning face", category: Category(group: "Smileys & Emotion", subgroup: "face-smiling"), isNew: false, zwjGroup: nil),
// 4K of those
]

the types:

struct Category {
    var group: String
    var subgroup: String
}

struct Emoji {
    var character: String
    var name: String
    var category: Category
    var isNew: Bool
    var zwjGroup: String?
}

It would be extremely rare anyone would want to write 4K of such lines, but still, quadratic CPU time complexity aside, quite questionable memory complexity (like 10 MB per expression?!) is ... unexpectable to put it mildly. Highly likely there's a memory leak in there. It's a bug worth filing.

1 Like