Good thread. I've been confused on when to use classes versus structs. The WWDC videos I've watched appeared contradictory. Perhaps, we can iron this out -- here is my core dump. :p
If the struct is small and contains value types it will be faster. (as suggested earlier) From what I've read/studied that appears to be the case. If the struct has a reference type within it, then you might want to box that reference in a struct and avoid a allocation if the struct its a member of is copied.
Its my understanding the justification to use structs is to avoid heap allocations -- structs use stack memory. This memory is already allocated. So, the position of the top of the stack is just incremented. This is extremely fast. This is the main argument to use structs.
The heap is a constrained shared resource with potential locking. That is, if different threads are allocating, deallocting, reading etc. there is a lock around the heap. Thus, creating a class reference type is always going to be more constrained on using this resource and less performant. For instance, Games might allocate upfront just avoid this with a custom memory scheme in c/c++. So, the problem was already there in c land prior to Swift. The stack avoids this mumbo jumbo.
But ( here is the catch and confusion for me ) if the Swift struct is too big, then Swift is going to put part of it into the heap anyways -- well thats locking and slow down. ( Swift makes tables internally that reference the heap and is transparent ) I recollect it might have to do with the size of a stack frame which limits what can be stuffed into the stack? As suggested earlier, you want small structs to avoid that. So, when people say always use structs, I tend to get confused because it can't be true that its always faster.
For instance, if I have a struct with 100,000 value type Doubles in it and I change just one of those Doubles, then the entire struct will get copied (Value Type) not only on the stack but the heap too because its a "big" struct? Though, if I'm just passing the struct around, then I can use cow (copy on write) and work around if its only being read.
Also, I've heard Arrays are value types but internally they are really referenced. Like if I have a buffer pointer I'm passing to c that is an Array in Swift. So, Arrays are not really purely Value types either?