开发者

How to change the amount of building threads in Xcode?

I'm building a couple of C++ files in xcode that take a lot of memory to compile (+1 GB / file). Because I do this on my dual core laptop, xcode uses 2 threads for building. The two threads will eventually be building the files that take 开发者_JAVA技巧a lot of memory simultaneously so the system suffers memory starvation and the compilation grinds to a near halt.

A sufficient solution for me would be to force Xcode to use only one build thread. Does anybody know a way to change how many build threads Xcode uses?

For those who are interested, the C++ files contain a sizable boost::spirit::qi parser.


The number of threads Xcode is using to perform tasks is controlled by PBXNumberOfParallelBuildSubtasks option. You can change it with the following command: - defaults write com.apple.Xcode <key> <value>. For example:

defaults write com.apple.Xcode PBXNumberOfParallelBuildSubtasks 8

See Xcode User Defaults for more details.

There are also many other ways to speed up a compilation, from precompiled headers to distributed builds. Read Reducing Build Times for more information on this.

Good luck!


With XCode 5, you can use -parallelizeTargets and -jobs NUMBER with xcodebuild. According to xcodebuild --help:

-parallelizeTargets     build independent targets in parallel
-jobs NUMBER            specify the maximum number of concurrent build operations


For Xcode 4 you must set the IDEBuildOperationMaxNumberOfConcurrentCompileTasks user default, for example:

defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4

Note the "dt". This won't affect xcodebuild on the command line. To do that, use something like

xcodebuild -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=4 ...

(See http://lists.apple.com/archives/xcode-users/2011/Apr/msg00403.html and http://lists.apple.com/archives/xcode-users/2011/Jul//msg00377.html )


A single build task should never do the same work twice, and certainly not simultaneously! Factor out the massive chunk of common code into a static library so it can be recompiled only when it changes. Set a target dependency in your application on the static library and link in the static library product. Changes to the rest of your application will then no longer require rebuilding the static library, which should speed up build times tremendously.

Try to exhaust all project-level solutions before manipulating Xcode as a whole. It is too easy to cripple Xcode to using only a single thread and forget to change it back when you move on to a new project. The Xcode User Default Reference documents many options that are not exposed via the Preferences interface, including:

  • PBXNumberOfParallelBuildSubtasks (positive integer)

    This allows you to limit Xcode to using only n build threads on every project it compiles.

  • BuildSystemCacheSizeInMegabytes (positive integer, default 1024)

  • BuildSystemCacheMinimumRemovalAgeInHours (positive integer, default 24)

    Upping the PCH cache size and retention time could help speed up your builds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜