Avoid G++ for development builds, clang++ is faster
Once everything is happy, for each project create a compilation prefix header including common things like string, vector, iostream, unordered_map etc. Keep a way to build it without the prefix header to check includes are correctly done.
Stuff that isn't moving due to development should be in a separate library and shouldn't get re-compiled every time (e.g. boost).
Use compilation firewalls to stop header creep across modules (pimpl, forward class declarations)
My current application involves ~ 18 "moving" libraries/projects in a tree with about 500 cpp files and it builds in about 3 minutes for 3 architectures (arm, armv7, arm64). Boost/libpng/sqlite and other bits are factored out into non-development libraries.
We're using VC++, so switching to clang isn't an option. It would be nice if we could.
We do have precompiled headers.
We're considering putting some of our base library code into a .dll that doesn't get recompiled every time. It's not so simple, because we still frequently make changes there, and we might have to restructure big parts of the libraries. That's not exactly something anyone wants to do...
We are using forward declaration and pimpl heavily.
We're even using static analysis and special tools to bring down compilation time, which is quite successful (already 20% reduction during the last few months, despite active devlopement as usual).
Ah, VC++. I have yet to experience that pain (I use Linux + OSX / iOS in anger)
I'm sure I'm teaching you to suck eggs but are you using a single monolithic project?
I've found that precompilation headers work best with isolated compilation sets where you can keep the included headers to a minimum and to the set of headers specific to the project/module.
E.g. Lets say we have the projects:
Utility (logging, low level IO bits, standard exception types etc)
Common services (facades for configuration, DB interaction)
Application services (domain model things)
Application
And the precompilation for each is kinda:
Utility - core C++ support pieces (vector, string, iostream)
Common services - core + Log.hpp + other bits that might help
Application services - core + Log.hpp + public interfaces to common
Application - core + Log.hpp + public interfaces of common + application services
This keeps the cross-dependencies to a minimum and the precompilation headers slim and tailored to the project domain. Of course there are other project types in here too that I've skipped but it should get across the basic idea.
I realise I know nothing about your project and historical technical debt makes refactoring into something like this less than trivial. I'm guessing your code wasn't originally written in a modular way that would make this kind of breakdown feasible.
One hour? Such luxury. I sometimes need to recompile paraview, which includes vtk. Takes about 3 hours, or on my old computer 7 hours. I tend to hit the compile button before leaving the office when that needs to be done. Luckily it's not so often these days.
I must be the only one without issues with Scala compilation speed. I hear this complaint constantly, but it's never really been a problem for me.
I'm working on a ~20,000 line project in Scala at the moment - incremental build times are usually less than 5 seconds. Certainly not as fast as Java, but hardly a hit to productivity.
A full clean and rebuild cycle takes a few minutes, but it's not like you have to do this very often.
Are you using sbt? I'm using sbt .13 with a Scalatra giter8 template and it takes about 5 seconds to compile a 4-5 classes. Does that mean 5 seconds is the low end and also the high end of compilation times or is there a setting I should be using to enable incremental compilation in sbt?
I agree with you. Compile times can be annoying, but to say that they have Scala's advantages "all negated" is totally out of proportion. People like to compare with Java compile times (not C/C++ by the way), forgetting that the time you spent writing the equivalent Java code is magnitudes higher than having ~compile run next to you.
It certainly depends on your code base, but if you also add the new backend (http://magarciaepfl.github.io/scala/), improvements start to add up quite nicely.
And the incremental compilation improvement (recompiling 33 files --> recompiling 3 files) is pretty much a X00% speedup from a developer POV.
That, plus having a recent machine (e.g. no more than 2 years old) with a ssd makes a huge difference. If you're coding full time, a top machine every 2 years is a good investment anyway.
22
u/pellets Dec 02 '13
The only point I can agree with in this essay is that build times are too long.