[swift-users] Passing value types or members of value types?

Daniel Dunbar daniel_dunbar at apple.com
Sun May 7 00:43:24 CDT 2017

> On May 6, 2017, at 10:39 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> On May 6, 2017, at 10:34 PM, Daniel Dunbar via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> To answer Kelvin's question, yes, the optimizer will be able to see through that code _assuming_ it can see the definition in a way it can optimize
> Kelvin, you should definitely take Daniel's word over mine on whether there's an optimization for this. I believe the rest of my explanation is correct.

Actually I think yours was more accurate... while it is is true the desired optimization will often take effect (given the conditions I describe), your's was correct that this isn't happening because the function signature is taking _fewer_ arguments. Rather, the optimizations works because the compiler will tend to inline that small function and then see it can discard the unnecessary data.

Whether or not this makes it worth boxing your struct to avoid large copies probably depends on how much you need to pass the struct through call sites which would in fact need to copy the full struct, versus inlining down to something smaller.

 - Daniel

> -- 
> Brent Royal-Gordon
> Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170506/8bed813c/attachment.html>

More information about the swift-users mailing list