Reputation: 2355
How can I profile and optimize the C++ Compile Times with Xcode?
I'm currently working on a C++ Game Project based on Cocos2d-x with 250+ Source Files. The compile time (without Cocos2d-x) is currently around 3.5 Minutes and I would like to find out where the compiler spends the most time and what I can do to optimize that.
I already did the most obvious things like always doing forward declarations and apply the "Include What You Use" paradigm.
The compiler is the latest Clang/LLVM of Xcode 8.
Upvotes: 1
Views: 1361
Reputation: 1628
Try creating a directory /tmp/xcode_build_timings
, and rebuild your project. (Don't forget to delete it afterward).
Upvotes: 4
Reputation: 4453
You can always try ccache. Working well within Xcode for me if I re-define CC
in the project settings. https://ccache.samba.org/
So, for example, install ccache via brew install ccache
.
Then make a script that you keep in your project's source control that is something like this:
#!/bin/sh
if type -p /usr/local/bin/ccache >/dev/null 2>&1; then
export CCACHE_CPP2=true
exec /usr/local/bin/ccache "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
else
exec "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
fi
call it "ccache-clang" for example. Storing this script in your project's source control means that you can check it out on another machine which does not have ccache installed, and then it will just use the default Clang compiler.
Then in Xcode, under Build Settings for your project, add a "User Defined" setting of "CC", ands et it to the path to your script. "${PROJECT_DIR}/ccache-clang
" for example.
This article is a great resource for getting this going. https://pspdfkit.com/blog/2015/ccache-for-fun-and-profit/
Upvotes: 2