在Xcode中使用Swift的编译时间非常长 [英] Extremely long compilation times with Swift in Xcode

查看:862
本文介绍了在Xcode中使用Swift的编译时间非常长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个iOS项目:


  • 第一个 - 使用Xcode 7.2编译的35k Swift LOC,Swift 2.1(或2.0?) .3

  • 第二个 - 15k Swift LOC,Swift 2.3,使用Xcode编译8.2.1

  • 第三个 - 15k Swift LOC,Swift 3.0,使用Xcode 8.2.1编译

所有这些的编译时间都很糟糕(干净构建10分钟以上),以及每一个的开发都在慢慢爬行。

The compile times for all of these are abysmal (10+ minutes for a clean build), and the development on each one of these is slowing to a crawl.

我已经尝试过:


  • 使用整体模块优化

  • C Dialect 更改为编译器默认值

  • 分析项目的构建时间并优化瓶颈(一些用数组连接编译6-10s的方法,nil合并操作符等),这些方法削减了15秒 - 完全没有显着差异

  • HEADERMAP_USES_VFS = YES

  • 其他一些我现在不记得了

  • Using Whole Module Optimization
  • Changing C Dialect to compiler default
  • Analyzing build times for the project and optimizing bottlenecks (a few methods that took 6-10s to compile with array concatenation, nil coalescing operators and such), which shaved like 15 seconds - completely unnoticeable difference
  • HEADERMAP_USES_VFS = YES
  • A few other I don't remember now

我正在使用SSD,8GB RAM& amp; 2.6ghz i5,如果重要的话。

I'm working on a Mac mini Late 2014 with an SSD, 8GB RAM & 2.6ghz i5, if that matters.

任何人都知道可能导致这种情况的原因,现在该怎么处理甚至是任何解决方法?从我在SO和其他地方看到的内容来看,这似乎是一个未解决的编译器问题。

Anyone knows what might cause that, what to do with that or even any workarounds for now? From what I've read on SO and other places, it seems like an unresolved compiler issue.

编辑:是的,我正在使用Cocoapods作为依赖项。我将尝试转移到Carthage,看看会发生什么。

Yes, I'm using Cocoapods for dependencies. I'll try moving to Carthage and see what happens.

推荐答案

尝试在Build Settings中设置以下内容作为解决方法。我假设您只有一个目标。

Try set the following in Build Settings as a workaround. I am assuming you have just one Target.


  1. 仅将Build Active Architecture设置为是。

  2. 将优化级别设置为无[-Onone]

  3. 添加名为SWIFT_WHOLE_MODULE_OPTIMIZATION的用户定义设置,值为YES

  4. 清空派生的数据和构建。

  1. Set the Build Active Architecture Only to Yes.
  2. Set Optimization Level to None [-Onone]
  3. Add User-Defined setting called "SWIFT_WHOLE_MODULE_OPTIMIZATION" with the value "YES"
  4. Empty your derived data and build.

然后,您还可以使用此工具分析任何缓慢编译的Swift文件: https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode

You can also then use this tool to analyze any slow compiling Swift files: https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode

我正在经历需要6-7分钟的构建时间。我离开Cocoapods并开始使用Carthage,这有助于清洁构建。即使这样,构建仍然需要3分钟。最大的改进来自我上面提到的步骤。

I was experiencing build times that were taking 6-7 minutes. I moved away from Cocoapods and started using Carthage which helped for clean builds. Even then builds were still taking 3 minutes. The biggest improvement came with the steps I mentioned above.

更新

在Debug版本中添加用户定义设置,将优化级别设置为快速,整个模块优化。然后在其他Swift Flags中为您的调试版本添加'-Onone'。

Instead of adding the User-Defined setting, on your Debug build set the Optimization Level to 'Fast, Whole Module Optimization'. Then in Other Swift Flags for your debug build add '-Onone'.

这篇关于在Xcode中使用Swift的编译时间非常长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆