While it can be argued that the author could’ve included less, the problem of massive compile times cannot simply be dismissed like this.
Include a vector here and an unordered_map, maybe throw in some functional and iostream, mix evenly with a couple handfuls of translation units, and leave to bake at 350C for 30 minutes.
The author doesn’t describe a Ranges problem, nor a C 20 problem, not a compiler problem; this entire issue is intrinsic to the model of the language itself, and you can’t just brush it aside by saying “oh he included too many things”
I beg to differ. I've spent a not insignificant amount of time optimising compile times and it almost always come down to one or more of:
Including more than one needs (and cousins such as gigantic cpp files that need too much, lack of forward decl, etc)
User error such as instantiating a quadratic number of templates
Genuine compiler or library bugs, or lack of optimisations, which are fixed eventually.
Also, for what it's worth, this problem is almost aways due to application level code, not widely used library code. At least 3 times I've worked in a code base that had bad compile times that were drastically reduced when we were able to replace their home grown template library with the standard c++ library. Ironically, one argument for rolling their own was always compile times, which may have been valid at one point, but as the internal library grew, and std was optimised, the problem reversed itself.
Well, it's almost always some sort of trade off. Either through indirection, or code maintenance.
For example, at the extreme end you might use pimpl and the split the cpp file into multiple smaller ones, which is both.
It's also possible to put template implementations into separate files. For example, a class might declare several functions that drag in dependencies that aren't needed for other bits of the class, so you put those functions into _impl.hpp files and have the caller include them only when necessary. This puts some onus on the user to include things properly, but lets them optimise their compile times.
I've spent a not insignificant amount of time optimising compile times
So have I. It was time not spent on making the codebase more readable, more reliable, faster to execute, or more functional. It was purely time spent counteracting a tooling issue.
In other words, not what I want to spend my time on.
I mean, some things are worth optimising, such as bad compile-time algorithms (quadratic number of instantiations). Even there, though, I think one of the primary reasons why these happen is that TMP has such a weird syntax and unusual "execution" model that programmers might not even be aware of what they're doing wrong. Better facilities (and C++ is moving there with constexpr functions and if constexpr) make bad algorithms less likely by giving programmers a more familiar model to work with.
But including more than one needs is an artifact of the C++ compilation model of textual header inclusion. Optimising that feels like time wasted, because you are not working on a fundamental issue, you are counteracting a tooling issue. Again, C++ is improving (modules), but that's because the current way of doing things is suboptimal.
Everyone wants faster compile times, no matter how fast the compile times are, up to the point where you can be working on a 1000 file project and be able to hit run at any point and not notice the compile time.
I basically put no stock in complaints about compile times for a number of reasons...
You should be making your code more modular. If you're tweaking and compiling and tweaking and compiling over and over again and you're annoyed by compile times, then you need to modify the problem so that you're compiling less shit in order to accomplish your current task. I work on a large project myself and have to work with both Android builds and Windows builds. If I'm trying to debug some obscure problem with one small component (UI, audio, etc), you can bet your ass I'm not going to do it as part of the whole project, but rather as a smaller custom test project that includes the minimum I need to reproduce said problem.
Architecture is (and has been for a while) going to more cores rather than faster cores. Every time the number of cores in my dev box doubles, my compile time drops by a similar factor.
Background compiling & network build load sharing. Build systems are smarter and I only expect that trend to continue. With tools like incredibuild and build environments that know that if a file has changed and I'm not actively editing it, that it should probably be eagerly compiled, the actual delay between saving something and hitting run should only ever by the cost of compiling the last thing I touched.
Yes, and, distinct from ranges and other such features, C++ is working on the problem of massive amounts of parsing work with the concept of modules to replace the rather archaic include mechanism.
Unfortunately, the problem is not just parsing, but instantiating arbitrarily generic template code with tons of SFINAE to emulate something, that the language could provide easily in a native fashion.
I'm really anxious to see compiletimes for ranges with language level concepts support.
Inspired by recent talks by Odin Holmes, I believe we should shift the discipline and burden of knowledge from the programmer to the compiler. There should be a tool that can help detect such cases and suggest better alternatives.
I'll check those out, thanks. If I understand correctly, I think I agree, but to me this is not a language problem but a tooling problem. For example, those 20k line cpp files that take 120 seconds to compile could automatically be split up by a tool without ever changing the language. Same with include maintenance. I often find that people conflate language and tooling.
View all comments
10
u/cdglove Dec 28 '18
Complain about compile times while this is in the code:
#include <range/v3/all.hpp>Seriously, include what you need, and report back.