<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 3, 2017, at 10:04 PM, Ray Fix via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">There was a great talk at WWDC 2016 about internals and Swift performance. &nbsp;<a href="https://developer.apple.com/videos/play/wwdc2016/416/" class="">https://developer.apple.com/videos/play/wwdc2016/416/</a></div><div class=""><br class=""></div><div class="">At one point, Arnold Schwaighofer says, "Copying of large values incurs heap allocation.” &nbsp;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.</div><div class=""><br class=""></div><div class="">My understanding is a value can get put on the heap if:</div><div class=""><br class=""></div><div class="">1) it is passed through a protocol and exceeds small size (3 words of storage)</div><div class="">2) it is captured by an escaping closure, and needs to extend lifetime</div><div class=""><br class=""></div><div class="">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.” &nbsp;Can this be detected with MemoryLayout&lt;BigStruct&gt;.size? &nbsp;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.</div><div class=""><br class=""></div><div class="">Any insights you have are greatly appreciated! 😃✨</div></div></div></blockquote><br class=""></div><div>No, Swift currently never implicitly puts parts of large structs on the heap. The heap allocation would come from the struct needing to be stored in something heap-allocated, such as a protocol container or capture box, like you said.</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>