Speedup from wrapping third-party libraries in C++20 modules

TL;DR: Wrapping third-party include-heavy libraries in C++ modules improved clean-and-build time by about 40% for both my laptop and desktop.
 

My desktop (which I haven't been able to use because of a leg injury), has like 20processor_threads each at 4.5GHz. Multiply that out, and you've got 90GHz-processor_threads. My laptop has 8processor_threads each at 2.0GHz for 16GHz-processor_threads. 90/16 is about 5.5, and I certainly feel the difference on this laptop.
 
I've been wanting to start using third-party c++ libraries as modules for a while now. There is a huge promise of build time speedup, but not all of the tools are in place for a library creator to provide their library as a module yet (via a package manager anyway).
 
I learned recently that you can pretty concisely export included symbols from a module. For example: Here is my wrapper module for a popular command line parsing library:
 

 

 

I was also recently forced to recognize just how slow including headers can be!

I had a few files (on this slow laptop) that took like 16 seconds to compile! They were like 20 lines but included four third-party, header-only libraries. Anyway, the first screenshot below shows the build time improvements after I wrapped the libraries fmt and cli11 in tiny modules and replaced all #inlcudes with imports.

I think only about 20ish files were affected, and my build time decreased by over 20%!

 

 

Next, I wrapped glm. It gets included in probably 80% of my translation units. The screenshot below shows the build time improvements. Build times dropped another 1.6min. So now, the total build time on my laptop (since adding wrapper modules for third party libraries, and if we only count .o generation) has decreased by 45%!

 

 

I ran the same comparison on my much more powerful desktop computer and found similar performance improvements!


 

I didn't measure the speedup for incremental changes, but those improved dramatically as well! I remember waiting around six seconds for DLL files to get hot-reloaded after making a small code change, and that duration is now short enough that I don't think about how long it takes!

Comments