I always use unity builds for all my projects now. That combined with using tcc as compiler (for C code) makes builds really fast. Another nice feature of unity builds is that I don't need to declare functions twice and keep the declarations synced. It's also nice to only have one place to find information about a function; people often put comments in header files that you can miss if you go to the definition. All o…
> Another nice feature of unity builds is that I don't need to declare functions twice and keep the declarations synced. What exactly leads you to have multiple declarations in sync, and thus creating the to "keep [multiple] declarations synced"?
Unity builds lurked into the Firefox Build System
31–40 of 64 posts
Re: Unity builds lurked into the Firefox Build System
#32I’ve been out of C/C++ development for a long time but seem to remember that precompiled headers were a thing back in the day. That approach didn’t have the name space issues pointed out here. Why are precompiled headers not used anymore?
About 20 years ago, on UNIX workloads we used to speed the compilation via ClearMake, a kind of distributed version of code cache that would plug into the compilers, however it has part of ClearCase SCM product.
On Windows, with Microsoft and Borland (nowadays Embarcadero), they work quite alright.
Also, modules will fix that, as per VC++ reports, importing the whole standard library (import std, as per C++23) takes a fraction of only including iostream.
Re: Unity builds lurked into the Firefox Build System
#33I’ve been out of C/C++ development for a long time but seem to remember that precompiled headers were a thing back in the day. That approach didn’t have the name space issues pointed out here. Why are precompiled headers not used anymore?
Re: Unity builds lurked into the Firefox Build System
#34Interesting. I've been aware of this technique for years because of the SQLite Amalgamation, but that was always sold as a way to simplify distribution and perhaps improve performance of the binary. I hadn't considered it as a build speed optimization, though that seems somewhat obvious in hindsight.
> I hadn't considered it as a build speed optimization, though that seems somewhat obvious in hindsight. Some build systems like cmake already support unity builds, as this is a popular strategy to speed up builds. Nevertheless, if speed is the main concern them it's preferable to just use a build cache like ccache, and modularize a project appropriately.
Also, does ccache work with MSVC?
Re: Unity builds lurked into the Firefox Build System
#35Re: Unity builds lurked into the Firefox Build System
#36> This generally leads to faster compilation time in part because it aggregates the cost of parsing the same headers over and over. But this also reduces the opportunity to parallelize compilation across multiple files because they have been concatenated into fewer build units, and each unit now requires more memory to deal with the non-header parts. For some build systems and repositories, this actually increases bu…
On very large projects you can always cut them into several libraries, and compile them on different cores. Quite easy to do in practice.
Re: Unity builds lurked into the Firefox Build System
#37Re: Unity builds lurked into the Firefox Build System
#38Re: Unity builds lurked into the Firefox Build System
#39It really boils down to two rules:
1. Don't declare anything in header files that is only used in one compilation unit. Internal structs and functions should be declared and defined in source files, and internal linkage used wherever possible. gcc and clang's -fvisibility=hidden is useful here.
2. The more frequently a header file is included (whether transitively or directly), the more it should be split up. If a "common" or "utility" header file is included in 10000 source files, then any struct, function, etc. that you add to that file will have to be parsed 10000 times by the compiler every time you build from scratch, even if only 10 source files actually use the struct/function that you added. gcc and clang's -H flag is useful here.
[1] https://lore.kernel.org/lkml/YdIfz+LMewetSaEB@gmail.com/
Re: Unity builds lurked into the Firefox Build System
#40So many hacks in compilers to try to work around this. A shame there is no language level fix for this nonsense.
Really wish there could be a C++—- that would improve on C in areas like this, and avoid all the incredible nonsense of C++. And no, not Rust or Go.