<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Yes, it's best to avoid concatenating strings with +. Not only for performance reasons, but it's also less readable than string interpolation:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">str += "No: \(count), HostIp: \(clientIp ?? "?") at port: \(service ?? "?")\n"</span></font></div></div><div><br>On 23 Mar 2017, at 08:11, Rien via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span>Thanks for that link, used it to track down the worst compile time offender:</span><br><span></span><br><span>This piece of code:</span><br><span></span><br><span>public func logAddrInfoIPAddresses(_ infoPtr: UnsafeMutablePointer&lt;addrinfo&gt;) -&gt; String {</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;let addrInfoNil: UnsafeMutablePointer&lt;addrinfo&gt;? = nil</span><br><span> &nbsp;&nbsp;&nbsp;var count: Int = 0</span><br><span> &nbsp;&nbsp;&nbsp;var info: UnsafeMutablePointer&lt;addrinfo&gt; = infoPtr</span><br><span> &nbsp;&nbsp;&nbsp;var str: String = ""</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;while info != addrInfoNil {</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let (clientIp, service) = sockaddrDescription(info.pointee.ai_addr)</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str += "No: \(count), HostIp: " + (clientIp ?? "?") + " at port: " + (service ?? "?") + "\n"</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count += 1</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info = info.pointee.ai_next</span><br><span> &nbsp;&nbsp;&nbsp;}</span><br><span> &nbsp;&nbsp;&nbsp;return str</span><br><span>}</span><br><span></span><br><span>Took 38 seconds to compile.</span><br><span></span><br><span>Removing the “str” assignment:</span><br><span></span><br><span>public func logAddrInfoIPAddresses(_ infoPtr: UnsafeMutablePointer&lt;addrinfo&gt;) -&gt; String {</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;let addrInfoNil: UnsafeMutablePointer&lt;addrinfo&gt;? = nil</span><br><span> &nbsp;&nbsp;&nbsp;var count: Int = 0</span><br><span> &nbsp;&nbsp;&nbsp;var info: UnsafeMutablePointer&lt;addrinfo&gt; = infoPtr</span><br><span> &nbsp;&nbsp;&nbsp;var str: String = ""</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;while info != addrInfoNil {</span><br><span></span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let (clientIp, service) = sockaddrDescription(info.pointee.ai_addr)</span><br><span>// &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str += "No: \(count), HostIp: " + (clientIp ?? "?") + " at port: " + (service ?? "?") + "\n"</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count += 1</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info = info.pointee.ai_next</span><br><span> &nbsp;&nbsp;&nbsp;}</span><br><span> &nbsp;&nbsp;&nbsp;return str</span><br><span>}</span><br><span></span><br><span>Brought it down to 6.6ms</span><br><span></span><br><span>Obviously I have to rewrite, but it does show how just one line of code can be responsible for approx 80% of the compile time.</span><br><span></span><br><span>Regards,</span><br><span>Rien</span><br><span></span><br><span>Site: <a href="http://balancingrock.nl">http://balancingrock.nl</a></span><br><span>Blog: <a href="http://swiftrien.blogspot.com">http://swiftrien.blogspot.com</a></span><br><span>Github: <a href="http://github.com/Balancingrock">http://github.com/Balancingrock</a></span><br><span>Project: <a href="http://swiftfire.nl">http://swiftfire.nl</a></span><br><span></span><br><span></span><br><span></span><br><span></span><br><span></span><br><blockquote type="cite"><span>On 22 Mar 2017, at 23:41, Greg Parker via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>On Mar 22, 2017, at 1:03 PM, piotr gorzelany via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Hi, I hope I reached the right mailing list to ask a question about tooling.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Can somebody from the compiler or Xcode team share some tips on how to improve compilation times of larger Swift projects?</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>I am an iOS developer and the largest issue my team has with Swift so far is that when the project gets semi large (~30 000 lines) the compilation times start to be high (~10 minutes from clean). This is a MAJOR downside since iOS development oftentimes requires rapid changes to UI or logic. Every person of my team compiles a project at least 10 times a day to test new features or functionalities. When compilation times start to be higher than 10 minutes that gets us to ~1.5h a day of developer time spend just on compiling. Not to mention the focus lost when this is happening.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>I know the Swift Evolution list is buzzing with new ideas and features but from my experience the compilation times is a CRITICAL thing to improve in the next Swift release since it cost real money to waste all those developer hours. Just think of all the hours lost on compiling across all Swift devs worldwide and you will get to probably dozens of thousand of dev hours a day.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Is the core compiler team going to address compilation performance in the next release?</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Maybe there is an existing solution to long compilation times that we don't know of? It would be great if anybody could share.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>I was thinking maybe of dividing the app into multiple frameworks since I think frameworks are compiled only once only on change?</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Build time is always a goal. Pretty much every version of Swift has had changes intended to improve compilation time or decrease the frequency of recompilation.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Often a large part of the build time is spent in a handful of places where the compiler's type inference system behaves poorly. You can use the -debug-time-function-bodies and -debug-time-expression-type-checking flags to look for these places. You can often get huge decreases in compile time by adding an explicit type declaration in the right place in order to simplify the type inference engine's job.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Here's a walkthough of one such analysis:</span><br></blockquote><blockquote type="cite"><span>Profiling your Swift compilation times</span><br></blockquote><blockquote type="cite"><span><a href="http://irace.me/swift-profiling">http://irace.me/swift-profiling</a></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>-- </span><br></blockquote><blockquote type="cite"><span>Greg Parker &nbsp;&nbsp;&nbsp;&nbsp;<a href="mailto:gparker@apple.com">gparker@apple.com</a> &nbsp;&nbsp;&nbsp;&nbsp;Runtime Wrangler</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>_______________________________________________</span><br></blockquote><blockquote type="cite"><span>swift-users mailing list</span><br></blockquote><blockquote type="cite"><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br></blockquote><blockquote type="cite"><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></blockquote><span></span><br><span>_______________________________________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></div></blockquote></body></html>