编译时间非常慢 [英] Compile Time Incredibly Slow

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

问题描述

我的项目包含约350个Swift文件和约40个可可豆依赖项.

将整个项目迁移到Swift 3后,构建时间就变得令人难以置信,并且花了3分钟多的时间才能完全编译.
我注意到,如果在不更改任何文件的情况下进行重建,则它会在合理的时间内构建.但是,如果我添加一个新功能,则需要3分钟以上的时间.
Cocoapods似乎没有引起问题,因为它在Compiling Swift source files状态下延迟.

我按照进行了调查:

  1. 在目标的构建设置中为Other Swift Flags添加了-Xfrontend -debug-time-function-bodies标志

  2. 构建项目

  3. 将其复制到终端并运行pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -100

但是,我没有发现任何问题.编译时间最长的文件只有250ms.下一个最接近的时间是100毫秒,即使所有350个文件花费了250毫秒来编译,也总共只有73秒钟,与我看到的3分钟以上的构建相去甚远.


是什么原因导致了这么长的编译时间?

在更新到Xcode 8Swift 3之前从未如此缓慢.

解决方案

更新1:

我在不运行Swift 3转换的情况下创建了一个新项目,导入了我的Swift 3文件,但是构建时间保持不变.

更新2:

我已经尝试过SWIFT_WHOLE_MODULE_OPTIMIZATION = YES,但是一旦您对多个文件进行了更改,增量构建就会失败,并且会触发重新构建,持续4-5分钟以上.

更新3:

我现在将整个代码库从Swift 3重写为Swift 2.3.没什么区别,问题出在Xcode 8编译器上.

更新4:

我可以确认取消选中这两个 Xcode 8错误似乎与它如何检查文件之间的依赖关系有关.

更新5:

我已经将我的代码库从Swift 2.3转换为了Swift 3,因为Xcode 8.2 beta要求这样做,该beta应该包含一个修复程序,仅当发生很小的变化时,Xcode不会重建整个目标.(28892475 )".可悲的是,他们没有固定的bug和我的编译时间正好与相同.

原始帖子:

我没有足够的声誉来发表评论,但我仍然想分享一些资源.我已经在这种痛苦中停留了好几天,升级到Swift 3完全是一场灾难.

我正在使用它来跟踪慢速文件,即使像您一样,这也不是我的问题. xcode中的其他内容实际上需要4分钟才能完成: https://github.com/irskep/swift_compile_times_parser https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode

我还确保我没有任何swift不喜欢的lazy varsclosures.连接字符串等时请勿使用+ operator. 参见.. >

如果发现任何问题,我将更新此答案,使用Swift 3自动柜员机几乎是不可能的.

My project consists of ~350 Swift files and ~40 cocoa pod dependencies.

As soon as the entire project was migrated to Swift 3, build times have been INCREDIBLY slow and took a little over 3 minutes to completely compile.
I've noticed that if I rebuild after not changing any files, it builds within a reasonable amount of time. However, if I add a new function, it takes the 3+ minutes.
Cocoapods does not seem to be causing the problem as it delays on Compiling Swift source files state.

I followed this to investigate:

  1. Added the -Xfrontend -debug-time-function-bodies flag to my Other Swift Flags in my target's build settings

  2. Build the project

  3. Copied this into terminal and ran pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -100

However, I didn't see anything of concern. The file that took the longest to compile was only 250ms. The next closest was 100ms, even if all 350 files took 250ms to compile, that would only be a total of 73 seconds which is way off from the 3+ minute builds I am seeing.


What could be causing these long compile times?

It was never as slow before updating to Xcode 8 and Swift 3.

解决方案

Update 1:

I created a new project without running the Swift 3 conversion, imported my Swift 3 files, but the build time remains the same.

Update 2:

I've tried SWIFT_WHOLE_MODULE_OPTIMIZATION = YES, but as soon as you make changes to more than 1 file, the incremental build fails and it triggers a re-build which lasts for more than 4-5 minutes.

Update 3:

I've now re-written my entire code base from Swift 3 to Swift 2.3. It didn't make any difference, the problem lies with the Xcode 8 compiler.

Update 4:

I can confirm that unchecking these two will alleviate the pain for a while, the Xcode 8 bug does seem to be tied to how it checks dependencies between files.

Update 5:

I've converted my code base to Swift 3 from Swift 2.3 since Xcode 8.2 beta requires it, the beta should include a fix for "Xcode will not rebuild an entire target when only small changes have occurred. (28892475)". Sad to say, they haven't fixed the bug and my compile times are exactly the same with Xcode 8.2 Beta.

Original post:

I don't have enough reputation to comment, but I still wanted to share some resources. I've been stuck in this misery for days, upgrading to Swift 3 has been a complete disaster.

I'm using this to track slow files, even though just like you, that's not my problem. Something else in xcode is taking literally 4 minutes to complete: https://github.com/irskep/swift_compile_times_parser https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode

I've also made sure I don't have any lazy vars or closures that swift doesn't like. Don't use the + operator when concatenating strings, etc. see this.

I'll update this answer if I find anything, it's just about impossible to be productive with Swift 3 ATM.

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

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