为什么 xcodebuild 和 Xcode 4.2 这么慢?
我在一个相对较大的项目(几万行代码)上使用 Xcode 4.2,而且速度非常慢。编辑没问题,但每当我尝试编译项目(在 Xcode 中,或在命令行上使用 xcodebuild)时,我的机器(四核 i7 MacBook Pro,4 GB RAM)就会停止运行。我注意到,在启动 xcodebuild 后,它会立即生成超过 8 个 clang 进程,而不会启动“真正的”编译进程。到目前为止,在 Stout 上还没有看到任何 xcodebuild 输出。我尝试过减少并行构建进程的数量< /a>,但仍然有很多 clang 进程在开始时启动。该项目使用 6 或 7 个直接依赖的外部项目,并且可能有 120 个源文件。在 Xcode 3.2 下,该项目的编译速度非常快。发生什么事了?我怎样才能让 Xcode 再次变得更快呢?
I am using Xcode 4.2 on a relatively large project (a few ten thousand lines of code) and it is horribly slow. Editing is ok, but whenever I try to compile the project (in Xcode, or with xcodebuild on the command line), my machine (quad core i7 MacBook Pro, 4 GB RAM) crawls to a halt. I have noticed that directly after starting xcodebuild, it spawns more than 8 clang processes, without the "real" compile processes starting. No xcodebuild output is so far seen on stout. I've tried reducing the number of parallel build processes, but still lots of clang processes are launched at the beginning. The project uses 6 or 7 direct dependent external projects and has maybe 120 source files. Under Xcode 3.2 the project used to be compiled very quickly. What's happening? And how can I make Xcode fast again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我们大多数人有三个主要选择:
最简单的解决方案是恢复到 Xc3。是的,Xc4 比 Xc3 需要很多;内存、CPU、磁盘空间和 I/O。您必须确定最大的问题在哪里,以减少它对您的影响。
我最近买了一个新的MBP,物理核心是两倍,物理内存是两倍,升级到Lion,同时升级了Xc4。编译时间确实有所改善,但其余大部分实际上更慢,并且更需要资源。这根本不是人们对 IDE 的期望,它也不允许打开多个项目,并且还使用统一的工作区视图。
转向 Lion + Xc4 使我在以下所有类别中的硬件需求增加了一倍多:
内存
对于大多数使用 Xc4 和 Lion 的重要项目来说,4GB 现在太少了。你仍然可以减少这个。我的 2 台主要机器上有 8GB 和 10GB,Xc4 很容易消耗掉所有内存(但我的项目比你的更复杂,除非你写了很长的行)。无论如何,您可以通过以下方式减少这个问题:
CPU
Xcode 4 使用新的(更准确)完成解析器。
defaults
禁用代码感知索引(也减少了内存需求)。硬盘
这可以是速度/大小的平衡。
构建
在 Xc4 中,与 Xcode 并行的 xcodebuild 现在使工作量加倍(默认情况下有单独的构建目录)。在 Xc3 中,默认情况下是构建到相同的目的地。验证您的设置 - 如果您允许,Xcode 将执行大量冗余构建(例如,每个工作区/配置一个目标,而不是 Xc3 的平面构建模型)。
或者只是在抽屉里装满四核 MacMini,并将其用作专用或分布式构建器。
文件错误
(不言自明)
Most of us have three primary options:
The easiest solution is revert to Xc3. Yes, Xc4 requires a lot more than Xc3; memory, CPU, and disk space and I/O. You will have to determine where your biggest problems are to reduce the amount it affects you.
I recently bought a new MBP with twice the physical cores and twice the physical memory, upgraded to Lion and upgraded Xc4 at the same time. The compilation times did improve, but much of the rest is actually slower, and far more resource hungry. That's not at all what one would expect from an IDE which also disallows multiple open projects and also uses a unified workspace view.
The move to Lion + Xc4 more than doubled my hardware demands in all of the following categories:
Memory
4GB is now too little for most nontrivial projects using Xc4 and Lion. You can still reduce this. I have 8GB and 10GB on my main 2 machines, Xc4 consumes it all quite easily (but my projects are more complex than yours, unless you write reeaeaaaally long lines). Anyways, You can reduce this problem by:
CPU
Xcode 4 uses a new (more accurate) completion parser.
defaults
(also reduces memory demands).Hard Disk
This can be a speed/size balance.
Builds
In Xc4, xcodebuild parallel to Xcode now doubles the work (separate build dirs by default). In Xc3, the default was to build to the same destination. Verify your settings - Xcode will do a ton of redundant building, if you allow it (e.g. one target per workspace/config, rather than Xc3's flat build model).
Or just fill a drawer with quad core MacMinis and use that as a dedicated or distributed builder.
File Bugs
(self explanatory)
另一种可能的解决方案在某些情况下可能有助于加快 Xcode 4 的速度:就我而言,主要问题似乎是我的 build/ 文件夹中的四个文件意外地被我的 git 存储库签入。在编译过程中,Xcode 注意到构建文件夹发生了变化,并触发了 git。由于在我的例子中构建文件夹包含数千个文件,因此性能下降了。从 git 中完全删除 build/ 文件夹(无论如何都不应该被签入)可以大大减少编译时间和系统负载。性能仍然比 Xcode 3 慢,但比以前好得多。
One more possible solution that in some cases might help speed up Xcode 4: In my case, the main problem seems to have been that accidentally four files from my build/ folder had been checked in with my git repository. During compilation Xcode notices that the build folder changed, and triggers git. Since the build folder contains thousands of files in my case, the performance went down. Removing the build/ folder completely from git (shouldn't have been checked in anyway) reduced the compilation times and system load massively. Performance is still slower than with Xcode 3, but much better than before.
您可以在 XCode 首选项中打开分布式构建,并找到一些友好的人,他们将通过与您形成编译机器集群来帮助您构建应用程序。
有趣的是,即使他关闭了,与之前的问题相比,你的编译器仍然使用不同的算法/机制以惊人的速度构建你的应用程序;)
所以,这意味着苹果公司已经忘记了那些不这样做的孤独程序员。不团队合作,因此孤独编译场景纯粹是在版本 4.0 - 4.2 中测试的
You can switch on Distributed Building in XCode Preferences, and find some friendly person who will help you build your app by forming compilation machines cluster with you.
The funny thing is that even he is off, your compiler still uses different algorithm/mechanism to build you app in a blazing speed if compared to the problems before ;)
So, that means that they at Apple have forgotten about lonely programmers who don't work in teams and therefore lonely compilation scenario is purely tested in versions 4.0 - 4.2
关于“投入更多硬件”方法的快速说明..
摘要:通过进行重大硬件升级,我的速度略有提高
测试:在克隆的 MacBook 上构建/运行完全相同的项目(其中唯一的区别应该是他们的硬件)
旧 Macbook Air(1.86GHZ Core 2 Duo 仅 2GB RAM)
对比
全新 Macbook Pro(2.3GHZ Core i7 8GB RAM)
在 IPHONE 3GS 上构建
Macbook Air 1:00 - 1:15
Macbook Pro ~1:00
=>速度提升 0 至 0:15
在 IPHONE 4S 上构建
Macbook Pro ~0:35
Macbook Air ~0:50
=> 速度提升约 15 秒
**部分测试:两台机器之间的模拟器构建时间似乎存在显着差异
Quick Note Regarding 'Throw more hardware at it' approach..
SUMMARY: I experienced a SMALL speed increase from making a SIGNIFICANT hardware upgrade
Test: Build/Run the exact same project on cloned macbooks (where the only difference should be their hardware)
Old Macbook Air (1.86GHZ Core 2 Duo ONLY 2GB RAM)
vs
Brand New Macbook Pro (2.3GHZ Core i7 8GB RAM)
BUILDING ON IPHONE 3GS
Macbook Air 1:00 - 1:15
Macbook Pro ~1:00
=> 0 to 0:15 of speed increase
BUILDING ON IPHONE 4S
Macbook Pro ~0:35
Macbook Air ~0:50
=> ~15 seconds of speed increase
**Partially tested: There DOES apear to a significant difference between build times for the SIMULATOR between the 2 machines
缓慢的另一个罪魁祸首是插件。 Subversions 插件绝对扼杀我的 Xcode 性能。我按照这篇文章中的说明禁用它。 哇!
Another culprit for slowness is plugins. The Subversions plugin was absolutely killing my Xcode performance. I followed the instructions in this SO post to disable it. WHEW!