<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Ran into this over the summer. My understanding is that Michael Gottesman (CC’d) has been looking into pattern matching at +0.<div><br></div><div>The code in SILGenPattern needs to be reworked, but I found this problem intersects with the really old dynamic casting entry points in SILGen too which would seem to complicate a “simple fix”. It’d be good to hear what plans, if any, there are to address this. It would be a real win to clean all of this up.</div><div><br><div id="AppleMailSignature">~Robert Widmann </div><div><br>2017/12/28 14:27、Chris Lattner via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>>のメール:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class=""><moving to swift-dev, where most of the perf optimization people lurk></div><div class=""><br class=""></div><div class="">This is a great question, I’m not sure what the answer is: maybe it is a simple case missed by the arc optimizer?</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 27, 2017, at 9:19 PM, Félix Cloutier via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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; line-break: after-white-space;" class="">Running this on my MBP with 10 as the parameter: <a href="https://gist.github.com/zneak/ae33bb970a08632cfb2925e2049f9e7a" class="">https://gist.github.com/zneak/ae33bb970a08632cfb2925e2049f9e7a</a> <div class=""><br class=""></div><div class="">I get a runtime of about 10 seconds, 45% of which is spent in retain/release calls according to Instruments (!!), and at least half of that from Expr.count. Looking at the IR, Swift generously sprinkles retain/release calls through the outlined copy method:</div><div class=""><br class=""></div><div class=""><ul class="MailOutline"><li class="">`self` is retained at the beginning of `count`</li><li class="">The values that you get out of destructuring are retained</li><ul class=""><li class="">Of course, when you get `count` on these, they are retained again</li></ul></ul></div><div class=""><br class=""></div><div class="">Of course, Expr.count cannot modify itself or its subexpressions because the functions are not mutating; in fact, no function in that program can mutate an enum case. Why, then, is Swift retaining/releasing `self` and the values obtained from destructured patterns? They can't go away. Shouldn't we be getting guaranteed references instead of owning references?</div><div class=""><br class=""></div><div class="">That seems to hit pattern-matching-heavy programs with indirect cases pretty hard, and it's pretty frustrating because that seems to be about the nicest way to write this program, and there's no workaround from the developer's perspective. I don't think that this is a fatal flaw of refcounting, but unless I'm missing something, that's sub-par behavior.</div><div class=""><br class=""></div><div class="">Félix</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-dev mailing list</span><br><span><a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-dev">https://lists.swift.org/mailman/listinfo/swift-dev</a></span><br></div></blockquote></div></body></html>