3 ms·
At a minimum this can give you a much better and more modular version of precompiled headers. Because modules are guaranteed not to be affected by macros or ord
by mattnewport 12y ago
At a minimum this can give you a much better and more modular version of precompiled headers. Because modules are guaranteed not to be affected by macros or ordering of module imports in the importing translation units you can get a modularized version of precompiled headers.
Don't underestimate the cost of just reading in all that text and parsing it. Modules allow you to cache some pre-parsed AST or similar internal representation of any exported template definitions which should greatly reduce the cost of instantiating them in the importing translation unit due to savings in IO and parsing time. Importantly, importing translation units never even have to look at definitions they don't use whereas currently they have to fully parse everything that gets dragged in by the headers they include even if they only use a tiny subset of the functionality.
A module enabled STL with well implemented compiler and linker support should greatly reduce build times for codebases that make heavy use of STL by simply replacing #include <header> with import std.header. The proposal eliminates all the unnecessary overhead of templates (re-parsing huge amounts of text) and leaves only the necessary / desirable overhead (instantiation from some internal representation with the specific types used). It's that final instantiation that gives templates their runtime performance advantages over other models (like C# generics) so you wouldn't want to lose that.
- lomnakkus 12y agoExactly. Essentially this reduces the algorithmic complexity of compilation which is a huge boon given that even simple programs these days result in the (repeated) parsing of millions of lines of code. Instantiation of templates obviously won't change, but recursive traversal and repeated re-parsing of includes will be completely unnecessary as the compiler can trivially[1] cache the intermediate version. Which is as it should have been from the start, but then hindsight is 20-20. It's really an elegant solution considering the constraints they're working under. [1] Preprocessor macros don't leak from includers to includees, so headers become independent of each other.