Michael Long
Sep 30, 2023

--

Should be the performance of reference semantics.

One should also note that all of the types referenced have COW semantics as implemented in the code for that type.

The Swift compiler, however, can also choose to implement COW behavior on user-defined structs.

The compiler is sneaky. Given a large struct, it may copy a large value entirely when passing it to a function as a parameter. Or it might decide to elide the value and simply pass a reference. Or it might examine the destination and choose to simply pass a portion of the struct to that function.

Or it might choose to inline the function call and avoid the copy completely!

And yes, this article definitely qualifies as a "deep dive" ;)

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)