{"id":14298,"date":"2016-04-29T10:26:22","date_gmt":"2016-04-29T14:26:22","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14298"},"modified":"2016-05-11T11:46:45","modified_gmt":"2016-05-11T15:46:45","slug":"speeding-up-slow-swift-build-times","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/04\/29\/speeding-up-slow-swift-build-times\/","title":{"rendered":"Speeding Up Slow Swift Build Times"},"content":{"rendered":"<p><a href=\"https:\/\/spin.atomicobject.com\/2016\/04\/26\/swift-long-compile-time\/\">Matt Nedrich<\/a>:<\/p>\n<blockquote cite=\"https:\/\/spin.atomicobject.com\/2016\/04\/26\/swift-long-compile-time\/\"><p>Copy the above code into XCode, press &ldquo;build,&rdquo; and go get a coffee. Come back in 12 hours. Yes, the above dictionary literal code takes at least 12 hours to compile.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/thatthinginswift.com\/debug-long-compile-times-swift\/\">Nick O&rsquo;Neill<\/a>:<\/p>\n<blockquote cite=\"https:\/\/thatthinginswift.com\/debug-long-compile-times-swift\/\"><p>If you suspect that something is taking too long to compile in your Swift project, you should turn on the <code>debug-time-function-bodies<\/code> option for the compiler. In your project in Xcode, go to <strong>Build Settings<\/strong> and set <strong>Other Swift Flags<\/strong> to <code>-Xfrontend -debug-time-function-bodies<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>Now that we know type inference can be a problem here, we can investigate the problem areas, specify type information and try building again. In this case, simply defining the structure to be a <code>Dictionary&lt;String, AnyObject&gt;<\/code> brings our compile time for that function down to <strong>21.6ms<\/strong>. Even adding the rest of the employee objects back in doesn&rsquo;t meaningfully change the compile time. Problem solved! Hit the rest of the potential problem areas in your code and try adding type information to speed up the compile times for the rest of your project.<\/p><\/blockquote>\n<p>This particular case has just been <a href=\"https:\/\/github.com\/apple\/swift\/commit\/2cdd7d64e1e2add7bcfd5452d36e7f5fc6c86a03\">improved<\/a> for an upcoming Swift release.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/macguru17\/status\/725249065055870976\">Max Seelemann<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/macguru17\/status\/725249065055870976\"><p>Good to see these issues getting discovered and also eventually fixed. Maybe Swift 3 will be prime time ready?<\/p><\/blockquote>\n<p><a href=\"https:\/\/twitter.com\/mpweiher\/status\/725253663023882240\">Marcel Weiher<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/mpweiher\/status\/725253663023882240\"><p>Dunno. Scala is how many years old and the compile times are still shockingly abysmal.<\/p><\/blockquote>\n\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2014\/09\/13\/swift-1-0-performance-and-compilation-times\/\">Swift 1.0 Performance and Compilation Times<\/a>, <a href=\"http:\/\/mjtsai.com\/blog\/2016\/01\/08\/slow-swift-array-type-inference\/\">Slow Swift Array Type Inference<\/a>, <a href=\"http:\/\/mjtsai.com\/blog\/2016\/04\/21\/swift-type-checking-performance-case-study\/\">Swift Type-checking Performance Case Study<\/a>.<\/p>\n\n<p>Update (2016-05-11): <a href=\"https:\/\/engineering.tumblr.com\/post\/144151794436\/swift-compilation-reporting-at-tumblr\">Tumblr<\/a>:<\/p>\n<blockquote cite=\"https:\/\/engineering.tumblr.com\/post\/144151794436\/swift-compilation-reporting-at-tumblr\">\n<p>To address this, we decided to automate monitoring of compilation performance. The goal was to create a weekly job that would compile our project with specific debug flags, process the results, and email out the slowest compilation paths.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Matt Nedrich: Copy the above code into XCode, press &ldquo;build,&rdquo; and go get a coffee. Come back in 12 hours. Yes, the above dictionary literal code takes at least 12 hours to compile. Nick O&rsquo;Neill: If you suspect that something is taking too long to compile in your Swift project, you should turn on the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[255,46,71,901,226],"class_list":["post-14298","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-compiler","tag-languagedesign","tag-programming","tag-swift-programming-language","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14298"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14298\/revisions"}],"predecessor-version":[{"id":14504,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14298\/revisions\/14504"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}