4 ms·
While LLVM authors probably know best, I don't understand some of his criticisms on the "Inherently Non-Scalable" slide. • M headers with N source files -> M
by nkurz 14y ago
While LLVM authors probably know best, I don't understand some of his criticisms on the "Inherently Non-Scalable" slide.
• M headers with N source files -> M x N build cost
It's only MxN if there is no use of the "#ifndef _HEADER_H" workaround that he mentioned earlier. Wouldn't adding a preprocessor directive like "#include_once <header.h>" solve this? Alternatively, these guards could be added to the headers themselves without changing the preprocessor. This probably should be a parallel set of headers (#include <std/stdio.h>) to avoid breaking the rare cases that depend on multiple inclusions, but creating that set would be a simple mechanical translation.
• C++ templates exacerbate the problem
I'm mostly a C programmer, so I have no argument here.
• Precompiled headers are a terrible solution
Why is this? It likely would break the ability of headers to be conditional on previous #define statement, but since the proposal does this anyway it doesn't seem insurmountable. Along that lines, how does this proposal handle cases where one needs/wants conditional behavior in the header such as "#ifdef WINDOWS" or the like? And is caching headers during the same compilation also "terrible"?
- deleted 14y ago[deleted]
- VMG 14y agoIt's only MxN if there is no use of the "#ifndef _HEADER_H" workaround that he mentioned earlier. There still is a processing cost for evaluating the instruction
- lttlrck 14y agoFor GCC this is highly optimized: "The preprocessor notices such header files, so that if the header file appears in a subsequent #include directive and FOO is defined, then it is ignored and it doesn't preprocess or even re-open the file a second time. This is referred to as the multiple include optimization." http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
- pjmlp 14y agoExcept that the contents of foo.h might be different depending on where it is being included.
- sigil 14y agoInstead of "#ifndef _SOME_HOPEFULLY_UNIQUE_NAME_H" I've started using "#pragma once" -- it's likely supported by every compiler you care about. http://en.wikipedia.org/wiki/Pragma_once http://en.wikipedia.org/wiki/Pragma_once
- nkurz 14y agoThanks, I wasn't aware that it was that well supported. Reading more about this, I also learned that GCC supports the Obj-C once only #import in C and C++ as well.
- zb 14y agoThat can cause problems if a header is accessible by two different paths (which is not uncommon in a large project). Using both gives you maximum efficiency without sacrificing correctness, and it works everywhere.
- Symmetry 14y agoWouldn't adding a preprocessor directive like "#include_once <header.h>" solve this? No, that means that for foo.c a given header is only added once. It doesn't prevent bar.c from importing and recompiling that same header.
- haberman 14y ago> Wouldn't adding a preprocessor directive like "#include_once <header.h>" solve this? No -- the point is still that you recompile each header for each source file that uses it. Running the compiler N times (once for each source file) costs M x N, not M + N. > Why is this? I agree with you here, I think this dismissal of precompiled headers needs a more thorough explanation (but perhaps it was given orally in the talk).
- cozmic 14y ago> Why is this? To get any benefit from the use of precompiled headers at all, you need to include practically every single header in your project in your precompiled header. Doing this is the opposite of modular.... it tightly couples each of your N compilation units with each of the M modules (changing any one of the modules bundled in the pch will force you to recompile all compilation units using the pch.)
- saurik 14y agoThis is an implementation detail that is fixable without language changes: it is often the case that two header files are semantically disjoint and the compiler (partly the preprocessor: you'd have to more incrementally update the compile after each include) could keep track of these relationships so it could safely merge results later; it is certainly no harder than a "merge" comparison of two sorted token lists. Their goals do go past this (their issues about "resiliency"), but it is seems disingenuous to include these performance issues when there are less drastic solutions.
- nkurz 14y agoI don't follow. I'd think that for any given header, you would only have to recompile it if the #include dependencies listed in that file (or their subdependencies) changed. I'd hope that for most projects this is far from every header. When would this happen? It also seems like this would be a win even if only used for rarely-changing system headers. As shown in the slides, for small projects the lines of unchanging standard includes dwarf the project specific code. Wouldn't it be a big win to avoid parsing and compiling all of these?
- micampe 14y ago> Wouldn't adding a preprocessor directive like "#include_once <header.h>" solve this? Obj-C already has this: #import http://en.wikipedia.org/wiki/Objective-C#.23import http://en.wikipedia.org/wiki/Objective-C#.23import It’s just #include with built-in guards, but headers still have to be compiled once per compilation unit.
- aidenn0 14y agoRe: Precompiled headers It may be possible to do precompiled headers right. However, compiler vendors have been trying to do so since the mid 90s and haven't succeeded yet. The reason I personally like this proposal better than PCH is that it requires explicit use. You can slowly convert libraries to the import syntax while still #including other headers that require conditional stuff. Seriously, just converting all #include <anything from C++ STL or Boost> to this will save 10s of gigabytes of source from being compiled on some projects I've seen.
- to3m 14y agoPerhaps "terrible" is a bit strong, but precompiled headers are basically a hack. They can hardly compete with a proper redesign. I'm not sure what you'd do about the conditional behaviour, though - seems like something of an omission. I've found it handy, and it is used a lot by the Windows headers. (I don't recall seeing it much outside Windows, though - perhaps a case of "Unix doesn't use it, OS X doesn't use it, RISC-OS doesn't use it, AmigaOS doesn't use it, Windows DOES use it - OK, four to one, it's not important"? ;)
- acqq 14y ago>> Precompiled headers are a terrible solution > Why is this? Think about it: the header potentially depends on any "define" value defined before the header is processed. If we'd have modules that define interfaces that don't depend on macros, we can process all the definitions that make the module only once for all the obj files that depend on it. You typically don't need conditionals on if another module is used or not. You need conditionals to compile the whole application or the dynamic library some specific way, but that is also only once per the compilation of the whole application. At the moment there is really code that can include more times he same header to define different types, but these are extreme use cases, however most of the libraries would gain if they would be defined as "modules" definitions of which can be compiled only once per application build.