I'm working on a performance critical section, and it would be very useful to implement a wrapper pattern like so:
protocol MyProtocol {
var someValue: Int { get }
}
struct Wrapped: MyProtocol {
var someValue: Int
}
struct Wrapper: MyProtocol {
var wrapped: Wrapped
var someValue: Int {
return wrapped.someValue
}
}
So I can imagine that the compiler could optimize the access on Wrapper.someValue so that it would be equivalent to Wrapped.someValue since in either case this is essentially just a memory access at a fixed offset in the struct, but is this actually the case in practice, or is there additional overhead from this type of wrapping?