Can anyone confirm if there is actually a runtime performance cost to using

let foo: [Int] = []

vs

let foo = [Int]()

As suggested here: https://github.com/nicklockwood/SwiftFormat/issues/1887#issuecomment-3209626590

I'd be surprised if the compiler doesn't just optimize this out somehow, but I don't actually have any basis for that assumption.

[New Rule]: A standard style for empty collection inits · Issue #1887 · nicklockwood/SwiftFormat

Barring other considerations, these two forms mean the same thing for Array and Set: let x: [Int] = [] let x = [Int]() let y: Set<Int> = [] let y = Set<Int>() I don't see a rule to allow preferring...

GitHub
@nicklockwood My assumption was that the compiler would have treated both cases identically but a quick test showed different assembly codes for each option.
@joaop yep, that surprises me too. Although I'm not fluent enough in assembly to tell the significance of the differences.

@nicklockwood The main differences there are:
1. let x: [Int] = [] has one additional instruction loading 0 into a register (line 14 on the right)
2. They branch into different initialization routines (line 16 on the left or 17 on the right)

That doesn't necessarily mean it's less efficient though, I didn't inspect the different routines and it's possible the one called by let x = [Int]() will have that additional load internally.