Speeding up builds with pre-compiled prefix headers

I was googling around for ways to speed up OF build times in XCode and came across this page:

http://disanji.net/iOS-Doc/documentation/DeveloperTools/Conceptual/XcodeBuildSystem/800-Reducing-Build-Times/bs-speed-up-build.html

It explains the use of something called “Precompiled Prefix Headers” to prevent XCode from having to recompile all the header files included in your project on each build. I don’t fully grok the details, but it sounds like this might help with the slowest part of building OF projects after the first build: XCode parsing all the header files for OF itself.

I’m way out of my depth here with understanding if this would be helpful in OF or how to do it. Is this something we could do and would it do any good?

this looks really cool, and could potentially remove the need for the “54 things compiling…” every time you build a new OF project with xcode. at least, i think that’s what it would do…

is there any reason why oF isn’t a static lib in osx?
going the prefix header approach is pretty platform specific afaik, and would involve lots of source code changes.
isn’t there a way we can do like on vs2010 where openFrameworks project becomes compiled as a static lib with debug symbols

i’ve got a friend working on a project with me (from afar). i think he’s set up some sort of cmake with oF in osx (outside xcode) with the main lib setup as static linked. if so, i’ll ask if he can share when he’s got time.

OF is already a static lib, check out OF/libs/openFrameworksCompiled/lib/. but you still have to compile against all the headers, as long as you’re including ofMain.h

great! so why aren’t we using it properly?
h files dont explicitly compile (only via cpp files that include them)
so we should expect XCode to report ‘2 files to encode’ for a testApp.cpp/h/main.cpp

Perhaps we can change the example project generation script to have a (default option) of using the static lib rather than including the full openFrameworks project. and perhaps then the script would also be responsible for generating the lib, or are we shipping it?

this is fixed in the most recent generated projects. it should be across xcode 3 and 4. zach is still testing a few edge cases in 4 where xcode forces a recompile, i think.

Just wanted to say that this technique with use of gold linker on linux helped me to compile openFrameworks application under 1 second. See my blog post for details: http://procedural.tumblr.com/post/99687562723

2 Likes

Got this working in Visual Studio also

For a 2 file (main.cpp, ofApp.cpp) project with 1 line of code in draw
VS2015 / Xeon 6-core / x64 / Debg build:

Using PCH:

1> 283 ms ClCompile 1 calls 1> 3408 ms Link 1 calls ========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

Without

1> 3535 ms ClCompile 1 calls 1> 4977 ms Link 1 calls ========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

That’s a pretty drastic increase in speed for the compile stage. Linking is still quite heavy, but for larger projects (more than 2 cpp’s) the effect will be more pronounced.

some notes on how to do this (presumes within an addon, but easy to adapt for an app):

How do you turn off precompiled headers for add-ons? Is it a visual studio setting somewhere?

Nvm, got it to work after fiddling around with settings. Turns out I can “right click -> properties” on individual cpp files to use PCH while having the project default as don’t use PCH.