[swift-users] are large values (not passed through a protocol) ever put on the heap?

Ray Fix rayfix at gmail.com
Wed Jan 4 00:04:11 CST 2017


There was a great talk at WWDC 2016 about internals and Swift performance.  https://developer.apple.com/videos/play/wwdc2016/416/ <https://developer.apple.com/videos/play/wwdc2016/416/>

At one point, Arnold Schwaighofer says, "Copying of large values incurs heap allocation.”  What isn’t clear to me here is if he is still referring to just existential container types or in just large values in general.

My understanding is a value can get put on the heap if:

1) it is passed through a protocol and exceeds small size (3 words of storage)
2) it is captured by an escaping closure, and needs to extend lifetime

Suppose I make a large struct, and pass it as a parameter, is there a point where the compiler says, “Okay wise-guy, you are going on the heap now.”  Can this be detected with MemoryLayout<BigStruct>.size?  I have tried a couple experiments where I make beefy (1kB) structs in the playground but I never see the size suddenly dropping to a pointer size.

Any insights you have are greatly appreciated! 😃✨

Best wishes,
Ray

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


More information about the swift-users mailing list