编译时间慢得令人难以置信 [英] Compile Time Incredibly Slow

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

问题描述

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

一旦整个项目迁移到 Swift 3,构建时间就难以置信缓慢,完全编译需要 3 多分钟.
我注意到,如果我在不更改任何文件后重新构建,它会在合理的时间内构建.但是,如果我添加一个新功能,则需要 3 分钟以上.
Cocoapods 似乎没有引起问题,因为它延迟了编译 Swift 源文件 状态.

我按照

  • 将其复制到终端并运行 pbpaste |egrep '.[0-9]ms' |排序 -t "."-k 1 -n |尾 -100

  • 但是,我没有看到任何令人担忧的事情.编译时间最长的文件只有 250 毫秒.下一个最接近的是 100 毫秒,即使所有 350 个文件都需要 250 毫秒来编译,那总共也只有 73 秒,这与我看到的 3 分钟以上的构建相差甚远.


    是什么导致了这些长编译时间?

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

    解决方案

    更新 1:

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

    更新 2:

    我已经尝试过 SWIFT_WHOLE_MODULE_OPTIMIZATION = YES,但是只要您对 1 个以上的文件进行更改,增量构建就会失败并触发持续时间超过 4-5 次的重新构建分钟.

    更新 3:

    我现在已经将我的整个代码库从 Swift 3 重写为 Swift 2.3.它没有任何区别,问题在于 Xcode 8 编译器.

    更新 4:

    我可以确认取消选中这两个 将暂时缓解痛苦,Xcode 8 错误似乎与检查文件之间的依赖关系的方式有关.

    更新 5:

    我已将我的代码库从 Swift 2.3 转换为 Swift 3,因为 Xcode 8.2 测试版需要它,测试版应该包含一个修复对于仅发生小的更改时,Xcode 将不会重建整个目标.(28892475)".遗憾的是,他们还没有修复错误,我的编译时间与 Xcode 8.2 Beta 完全相同.

    原帖:

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

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

    我还确保我没有任何 swift 不喜欢的 lazy varsclosures.连接字符串等时不要使用 + 运算符.看到这个.>

    如果我发现任何问题,我会更新这个答案,使用 Swift 3 ATM 几乎不可能提高效率.

    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天全站免登陆