We need to seriously think about what to do with C++ modules
10 days ago
- #Compilation
- #Modules
- #C++
- C++ modules should demonstrate a 5× to 10× compilation speedup to justify their existence; otherwise, they should be removed from the standard.
- The primary goal of C++ modules was faster compilation times, but focus has shifted to build isolation (preventing macro leakage, etc.), which is less critical for most developers.
- C++ modules were accepted into C++20 despite warnings about implementation difficulties, leading to a lack of functional implementations years later.
- Modules require tight integration between compilers and build systems, but the lack of a unified approach has resulted in fragmented and inefficient implementations.
- The design of C++ modules was overly ambitious and lacked real-world testing, leading to complexity and poor performance.
- An iterative approach to module development, starting with small-scale prototypes, would have been more effective.
- The 'import std' initiative aims to improve compilation speed by replacing standard library headers with modules, but gains may only match precompiled headers (10-20% speedup).
- A custom standard library experiment showed a 4× compilation speedup, suggesting 5× is a reasonable target for modules.
- Using modules introduces disadvantages like code rewrites, loss of portability, and increased build complexity.
- The C++ committee's focus should be on features that provide clear benefits without excessive trade-offs.