r/cpp • • Aug 09 '26

A failure to separate concerns

158 Upvotes

I've been taking a look at an extremely popular, 50K+ stars, C++ library which I won't name as I'm going to criticise it as an example of a wider problem.

This is going to be a rant and there may even be sarcasm. Feel free to skip it if that upsets you.

This library is sponsored by a long list of companies. It's incredibly widely used. It has 100% test coverage, builds with several different build systems, works on several platform, complies with all the standards, linters and clang-tidy you can imagine. It's clearly aiming to be part of the future C++ standard and it might even make it. In short it's brilliantly written with a massive amount of effort put into it. One of the highest quality C++ libraries out there, that isn't actually part of Boost or the standard itself. In terms of how robust, well tested and well supported it is.

So what's the problem?

This library has one job, to deal with a particular text format. To parse that data into useful objects and transform those objects back into text. That's it, that's all anyone will ever use it for and if it does that it achieves 100% of its design goals.
The 'useful objects' part of that sentence is doing some heavy lifting here as what is a useful object to one client might not be to another. So some flexibility in what objects are generated and what access methods they have is a reasonable extension point.

In such a library we'd expect to find a parser to get us from text to in memory objects. A generator to get from the in memory objects back to a text representation. We might also expect some Unicode adaptation to deal with what a 'text representation' means.

All these things are indeed present, although barely distinguishable from the vast sea of code in which they sit. I think we get 5 parsers for different dialects of the format. It's completely unclear how much code they share or if jamming them into one library is even a good idea. I literally can't find the generator so I don't know whether we get 1 or 5, or if it's possible to choose which dialect is output. Seems like basic stuff but why do basic stuff when there is so much more complicated stuff to do.

There are custom data structures. Useful but clearly belonging in their own library.
An internal binary representation type, exposed at the root of the include directory as if this was something you'd want to include.
Custom string concatenation because clearly concatenating strings is not a solved problem.
Code for integrating with Google libraries because that apparently belongs here.
Pre-processor macro blocks across hundreds of files for dealing with at least 4 different variants of C++. No physical separation of the C++20 code I can use from the no longer needed C++11, 14 & 17 code work arounds so I can ditch the dead code that isn't going in the binary anyway but remains all over my screen. No way to exclude experimental C++23 code except to find the right macro to nobble and the blocks of greyed out code that my compiler can't even read, remain in my way.

Of course this library does it's own compiler detection, poorly, and uses custom pre-processor macros, spread through the whole codebase, to determine if a long list of features are switched on or off.
Some of these are probably options I could set at compile time. Some are there to cope with old Clang versions that no one uses anymore. There's no list to say which is which, or which combinations of switches actually work. I expect massive effort has gone into testing thousands of combinations, that almost no one will ever know they are, or are not, using.

There's custom hashing because every library needs its own copy of a hashing algorithm, just in case the one they copied it from breaks I suppose.

Lots of custom exception classes, even though exceptions are apparently optional, so you'd think they might only be optionally in the project.

There are macros for the namespaces. Why not, it's got every chance of working if you turn those off, lol, No.

std::filesystem is apparently either experimental or in some way optional and there's a separate macro to turn I/O support on and off. No explanation as to why there's any file I/O at all in a library to transform text to objects and back again.
I happen to like to use async I/O so I guess I'd build with I/O support off and then hack in my own. No thanks.

Everything is of course wrapped in a massive amount of template meta programming so that almost nothing in this header only library exists as a concrete type, until you instantiate it in your code. You literally can't definitively reason about the code without first writing something that uses it.

Yet despite this apparently total flexibility it manages to bake in a whole set of assumptions I don't want. std::allocator use is mandatory despite there being no reason, in principle, why this library should even do memory allocation. Why not externalise it and make it somebody else's problem?
There are only the known container types from the standard library. If you want to parse the data into any of those you're golden but anything else, like the very same custom ordered map type that the library itself relies on, and you're overloading meta templates until the middle of next week.

Did I mention that this entire mess is header only. Easy to include and all that. This also means of course that every type, every constant, every function, every template and every macro from these many, many thousands of lines of code ends up in every TU where you include the header. Including all the compiler mitigation macros that are never going to clash with the ones in that other library you want to use. That sort of thing has never been known to cause any issues or slow down builds or anything like that.

It's quietly admitted in the comments that it shouldn't be header only. Warnings have to be supressed to get away with being so. It doesn't need to be header only of course to have a single inclusion header in order to be 'easy to use'. They are NOT the same thing but why build your own binary when you can bloat thousands of others instead, right.

In summary there are thousands of lines of code in this library that don't belong here. This code, that does every job other than parse the target text format and regenerate it from in memory objects, should be in dependent libraries or just shouldn't exist. There are no dependent libraries of course because it's header only. This saves a single addition to the link line in clients while injecting many thousands of lines into every TU where one type from this library is needed. Thousands of lines that get parsed, generated and then mostly thrown away on every build.

The author, who clearly has brain power going spare, has made their job orders of magnitude more difficult than it needs to be by putting everything in their library on the actual API and having to support a lot more code than they need to. A ::detail namespace has never stopped anyone before and putting almost everything in it anyway is just a sign you've got too many details.
They've also made testing vastly more complex and support probably a full time job. Fine if you're being sponsored I suppose.

I know a little about writing large projects that do many things. This is not one of those. This is a single purpose library that aims to do one thing and do it well. Noble goals. It succeeds at the later while being an unmitigated disaster at the former.
The absolute failure to separate concerns is not a flaw in any way specific to this library though. It's almost completely ubiquitous. Pick any top rated C++ library you like on GitHub from HTTP Servers to graphics libraries and try assessing how much of it is actually doing what the library is about and how much is not. What assumptions about types and memory handling it's baking into the API and, crucially, the implementation.

I will repeat at this point for both irony and emphasis that this is an absolutely top quality library, written by someone far cleverer than me, that passes every metric our industry has. It is lauded as a great thing and used by thousands of other projects. Projects which are wasting hundreds of trillions of CPU cycles building code that probably isn't what they think it is, because they've no idea which bits are turned on or turned off in their build. Much of it isn't needed anyway and it's so complex that it's not worth anyone's time to ask difficult questions.

For a trivial use case this approach presents essentially no issues but really, is your use case trivial? I hope not. I expect your use case is pretty serious. You're building something larger and more important than a simple tool to read and write files in a particular format. I'm looking at this library for potential integration into a larger project. It's the industry standard and it's simply unusable.
This is apparently not only the best we can do but what's much, much worse, the best we expect to do.
Houston we have a problem...


r/cpp • • Aug 08 '26

GCC should ship prebuilt binary tarballs like LLVM

16 Upvotes

It is really annoying, when you wanna test something you can't just download a previous release like llvm, so it is very hard to check if there is a regression.

Also, the default build of c and c++ only, takes like an hour because of triple consecutive builds. So every time you have to lookup to that weird flag on the internet to turn that off.


r/cpp • • Aug 08 '26

Bjarne Stroustrup, creator of C++, joins Susquehanna

Thumbnail cppcon.org
114 Upvotes

r/cpp • • Aug 07 '26

GCC 16.2.0 Released

Thumbnail phoronix.com
168 Upvotes

I'm pretty excited about this maintenance release. I think this will be the first version of gcc which can compile my project.


r/cpp • • Aug 07 '26

Boost.Multi Multi Mini-Review Begins Today (7 Aug - 12 Aug)

20 Upvotes

Hello,

Today begins the mini-review of Multi, authored by Alfredo Correa. Multi is a modern C++ library that provides manipulation and access of data in multidimensional arrays for both CPU and GPU memory. The review will run through Wednesday 12 August.

You can find the library and documentation links below:
- https://github.com/correaa/boost-multi
- https://correaa.github.io/boost-multi/multi/intro.html

The review earlier this year raised a number of issues that primarily revolved around the state of the documentation, not the library itself. I have labeled all of the issues related to conditions found in last review, and many have notes or resolution from Alfredo:

https://github.com/correaa/boost-multi/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22Boost%20review%22

To this end the review will revolve around the current state of the documentation on the branch "boost_review". In your review please explicitly state if you recommend REJECT, ACCEPT, or a conditional acceptance along with the acceptance conditions.

Please let me know if you have any questions or concerns. Thank you in advance for your time.

Matt
Multi Review Manager

Edit: Link to the previous review thread is here: https://www.reddit.com/r/cpp/comments/1rlhm4g/boostmulti_review_begins_today/


r/cpp • • Aug 06 '26

C++ Show and Tell - August 2026

49 Upvotes

Use this thread to share anything you've written in C++. This includes:

  • a tool you've written
  • a game you've been working on
  • your first non-trivial C++ program

The rules of this thread are very straight forward:

  • The project must involve C++ in some way.
  • It must be something you (alone or with others) have done.
  • Please share a link, if applicable.
  • Please post images, if applicable.

If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.

Last month's thread: https://www.reddit.com/r/cpp/comments/1umnaxs/c_show_and_tell_july_2026/


r/cpp • • Aug 06 '26

Neoclassical C++ (2): Exploring input-output segmented algorithms

Thumbnail boostedcpp.net
24 Upvotes

Hi,

I've written a new blog entry continuing my previous article about segmented iterators. This time trying to analyze how to apply Matt Austern's segmented iterator pattern to input-output algorithms likecopy, copy_if, etc., benchmarking the experimental implementation from Boost.Container vs the standard library.

New article link: https://boostedcpp.net/2026/08/06/neoclassical-c-2-exploring-input-output-segmented-algorithms/

Happy to receive feedback!


r/cpp • • Aug 06 '26

C++26: #embed

Thumbnail sandordargo.com
137 Upvotes

r/cpp • • Aug 06 '26

Faster KNN search in Manticore: 2-pass HNSW, batched distances, and AVX-512

Thumbnail manticoresearch.com
2 Upvotes

Three changes to the HNSW search engine improve KNN throughput by up to 29% at high k, with over 20% gains under concurrent load. No API changes, no index rebuild, no configuration. Just faster searches.


r/cpp • • Aug 05 '26

C++26 Reflection: Simplifying JSON Serialization

Thumbnail techfortalk.co.uk
53 Upvotes

I have been exploring the new additions in C++26, and I have been discussing the reflection feature that has come with C++26. In the last post, I discussed what is reflection and how to use it and how to use it with a simple example, particularly with an enum class. Since then, there have been suggestions to provide an example which is more than a toy :). In this post, I have discussed how to use reflection for JSON serialization, which is something we often have to do. This example is somewhat taken from real-world code but has been stripped down significantly. Suggestions are always welcome.


r/cpp • • Aug 05 '26

C++Now C++Now 2026: A Path to Pratically Safe C++ talk by Google's C++ Safety Team

Thumbnail youtube.com
52 Upvotes

r/cpp • • Aug 05 '26

Boost.Int128 has been accepted

126 Upvotes

Boost.Int128 from Matt Borland has been accepted into Boost. Arnaud Becheler managed the review.


r/cpp • • Aug 05 '26

Faster Than Ninja

Thumbnail build2.org
65 Upvotes

r/cpp • • Aug 03 '26

Common Problems I see with Public Libraries Build Scripts

26 Upvotes

Hi, I'm an early user of Common Package Specification and C++ modules. I package and port libraries for my own use frequently.

I want to talk about issues I see constantly.

- Having specific options for sanitizers, exceptions etc, this is a toolchain problem, if I wanna build your library with sanitizers I can just add the flags to my cmake toolchain file same as allocators.

- Not separating build options to a separate file, meson already does this, it ain't that hard to do in cmake, just cache variables in a separate file at project dir which you include before subdirs

- Making tests separate cmake projects rather than just executables, just why?

- Vendoring dependencies, copy pasting files from other projects rather than just consuming these external libs via packages.

- Using unnecessary helper functions that really makes the cmake script unreadable. Build scripts don't need to be over engineered, they are just basic scripts in which you define very basic information.

I could go on but I'm tired.


r/cpp • • Aug 03 '26

Using Alpaka to GPU-Accelerate CAPOW: A Case Study, Wed, Aug 12, 2026, 6:00 PM

Thumbnail meetup.com
5 Upvotes

CAPOW is a continuous-valued cellular automata explorer with update loops that look GPU-friendly: one work item per cell, small-neighborhood stencils, ping-pong buffers, and pointwise nonlinear rules.

This month, Richard Thomson will present a case study in using Alpaka (An Abstraction Library for Parallel Kernel Acceleration) to move a CAPOW-like update rule onto CUDA without porting CAPOW itself. We'll walk through the spike: CMake/vcpkg setup, CUDA language support, the CPU reference path, the Alpaka CUDA kernel, correctness checks, timing results, and the parts that hurt.

The first pass showed zero CPU/GPU error and strong update-only speedups, including about 102x at 1000 x 1000 and 174x at 1920 x 1080 for the diffusion rule.

We'll also discuss whether Alpaka is earning its keep compared with writing direct CUDA.

This will be an online meeting, so drinks and snacks are on you!

Join the meeting here: https://meet.xmission.com/Utah-Cpp-Programmers


r/cpp • • Aug 03 '26

New C++ Conference Videos Released This Month - August 2026

10 Upvotes

C++Now

2026-07-27 - 2026-08-02

C++Online

2026-07-27 - 2026-08-02

ADC

2026-07-27 - 2026-08-02


r/cpp • • Aug 03 '26

Performance with custom data flexibility and no inheritance

7 Upvotes

I am in an argument. The goal was to have a structure with some base members, we can call it a `State node` in State machine, from which the user can add their own custom data on top, without using inheritance or dynamic casts. Would like the collection of different nodes to be stored in a vector in the end.

Obviously, we want to avoid std::vector<SomeType *>

It was suggested I use something like:

class State;
using TransitionHandler = void(*)(State *, const Event &);

template<typename T>
concept StateLike = requires(T s, const Event & e)
{
    { s.onEnter(e) } -> std::same_as<void>;
    { s.onExit(e) }  -> std::same_as<void>;
};

class State final
{
public:
    using StateId = uint32_t;
    StateId id_ = INVALID_ID;
    std::string name_;

    template<typename T>
    requires StateLike<T>
    static State create(std::string name, T & object)
    {
        return State
        {
            name,
            &object,
            [](State * state, const Event & e)
            {
                static_cast<T*>(state->instance_)->onEnter(e);
            },
            [](State * state, const Event & e) 
            {
                static_cast<T*>(state->instance_)->onExit(e);
            }
        };
    }

private:
    static constexpr StateId INVALID_ID = static_cast<StateId>(-1);
    void * instance_;                // user defined state

    State(std::string name, void * instance, TransitionHandler enter, TransitionHandler exit);
};

Now, if I understand things correctly, this will indeed allow the user to provide some custom struct/class as a template param when they create a State object and that State object is going to hold a pointer to it. When it is needed, it is going to call the `enter` and `exit` methods through that static cast.

That should indeed allow us to fill a vector with these State objects and circumvent the need for inheritance, but I wonder if it really performs any better. The collection is in contiguous memory when in the vector, so add, remove, and traversal should be fast. However, all the execution of calls on the State object is going to go through the pointer, which means executing methods on a State will not be part of that performance gain from living in contiguous memory.

Assuming I am always holding on to the current state(s) and that we build the state machine with all its states at startup, what have I really gained? Is there any performance increase at all?

I believe we just replaced the vtable cost with our own pointer, which is pretty much the same?


r/cpp • • Aug 02 '26

How fast is C++26's std::hive?

Thumbnail lemire.me
255 Upvotes

r/cpp • • Aug 01 '26

BeCPP Symposium 2026 - Bryce Adelstein Lelbach - The CUDA C++ Developer's Toolbox

Thumbnail youtu.be
38 Upvotes

r/cpp • • Jul 31 '26

Static Analysis Experiment with Reflection

32 Upvotes

I want to share a little experiment that I made using reflection. It’s a compile-time style checker using C++26 static reflection. It validates the conventions I use in my own projects (the H_ curried callable thing, Mut/Mov/Ref/Cpy qualifier aliases, plus class/namespace naming). Because reflection can’t properly see into uninstantiated templates yet, I had to write a parser for GCC's display_string_of to extract templates, qualifiers, return types, and requires clauses. Given this weakness it's not a particularly production-ready tool. It could be done with a clang-tidy script, but I learned a few things just from trying to answer "Is it possible? What exactly can I inspect right now?". Unfortunately, we don't have code generation yet so there is a bunch of boilerplate that the user needs to write.

The rationale of the conventions (mainly Mut/Mov/Ref/Cpy) is in GUIDELINES.md. The gory implementation details (and my field notes on GCC bugs) are in VIRACOCHA.md.

https://github.com/NotRiemannCousin/Viracocha/blob/master/VIRACOCHA.md


r/cpp • • Jul 31 '26

Interconverting std::function with copyable_function – Arthur O'Dwyer

Thumbnail quuxplusone.github.io
45 Upvotes

The article shows how converting std::function to std::copyable_function (or vice versa) leads to slower performance and increased memory usage each time the conversion occurs.


r/cpp • • Jul 31 '26

ranges and views for stack, queue, and priority_queue

18 Upvotes

I've always felt that exposing iterators for std::stack or std::queue doesn't quite make sense because iterating over them would typically change their state.

That said, the range features introduced in C++20/23 are just too tempting. 😄

I bet many C++ developers have had this thought at least once:

queue | views::values | views::to<std::vector>()

...or more generally, "What if I could use the ranges pipeline directly on a queue or stack?"

So I spent some time experimenting to see if I could make it work. Here's what I came up with.

https://cognosnotes.com/blog/cpp-pop-range

Edited:

An upgraded version is introduced at https://cognosnotes.com/blog/cpp-pop-range-addendum

Thank you u/SirClueless for the great advice.


r/cpp • • Jul 29 '26

Build timings from auto-modularised VS solution with external and internal libs

19 Upvotes

To investigate how well modules work with MSVC without rewriting projects and putting up with malfunctioning intellisense, I made a little python script to modularise a whole VS solution (yes, I made it, using real bio-neurons).

The script lets me try out different modularisation strategies on a VS Solution on a per-project basis:

  • Header-based, don't modularise. If dependencies are modules, they will be imported.
  • PartitionsMI: Partition-per-header using standard module cpp units.
  • PartitionsPI: Partition-per-header using MSVC partition cpp units.
  • Submodules: Module-per-header
  • SubmodulesII: Move implementation to interface (not always possible due to cyclic imports)

Modularised code is surrounded with extern "C++" { export {.

The code is a super secret incomplete game engine/game. But here's some info:

  • External libs, including: Boost (unordered flat map), std, d3d, imgui, physx, spdlog, <windows>.

    • Wrapper module for each.
  • Solution projects: CommonStuff, Scripting, GameData, Graphics, Anim, SceneGraph, SceneManager, Entity, App

    • Some projects don't have much code. Others have quite a bit. Enough to give the build system something to parallelise.

All projects built using debug config. Benchmarks average 3 or more timings, outliers ignored. CPU is 12600, 12 threads. Multipliers are speedup.

 CommonStuffScriptingGameDataGraphicsAnimSceneGraphSceneManagerEntity
Header-based, no pch4.59s5.68s7.46s2.92s40.74s24.94s2.86s3.19s
Header-based, pch3.61s5.30s6.55s19.38s12.53s
Extlib modules + CommonStuff submodules3.60s4.78s1.62s18.55s9.41s1.57s2.09s
PartitionsMI4.25s8.09s2.54s
PartitionsPI4.02s6.04s7.09s2.53s33.83s15.97s2.66s4.10s
Submodules3.59s4.75s6.05s2.26s26.80s14.31s2.12s3.15s
SubmodulesII3.44s7.93s
 CommonStuffScriptingGameDataGraphicsAnimSceneGraphSceneManagerEntity
Header-based, no pch1.00x1.00x1.00x1.00x1.00x1.00x1.00x1.00x
Header-based, pch1.27x1.07x1.14x2.10x1.99x
Extlib modules + CommonStuff submodules1.58x1.56x1.80x2.20x2.65x1.82x1.53x
PartitionsMI1.08x0.92x1.15x
PartitionsPI1.14x0.94x1.05x1.15x1.20x1.56x1.08x0.78x
Submodules1.28x1.20x1.23x1.29x1.52x1.74x1.35x1.01x
SubmodulesII1.33x0.94x
 AppSingle fileFull Rebuild AppSingle fileFull Rebuild
Header-based, no pch65.19s3.97s145.49s1.00x1.00x1.00x
Header-based, app pch24.74s2.15s108.92s2.64x1.85x1.34x
Header-based, mostly pch78.87s1.84x
Extlib modules26.82s2.35s58.89s2.43x1.69x2.47x
Extlib modules + CommonStuff partitions25.89s2.47s2.52x1.61x
Extlib modules + CommonStuff submodules24.53s2.23s57.50s2.66x1.78x2.53x
Extlib modules + most libs as submodules31.14s2.97s2.09x1.34x
Full submodules, except app34.61s2.95s88.90s1.88x1.35x1.64x
Full submodules64.02s6.22s142.98s1.02x0.64x1.02x
  • "Most libs" = CommonStuff + Scripting + GameData + Graphics + Anim + SceneGraph.
  • "Mostly pch" = PCH for CommonStuff, Scripting, GameData, Anim, SceneGraph, App.
  • "Single file" is recompiling one moderately complex file in App. ~930 lines, lots of includes.
  • "Full Rebuild" excludes extlib module wrappers.

Detailed timings of CommonStuff:

Header-based:

	1>      210 ms  LIB                                        1 calls
	1>     4459 ms  CL                                         2 calls
	04.874 seconds
	
PartitionsMI:

	1>      125 ms  LIB                                        1 calls
	1>      199 ms  MSBuild                                   16 calls
	1>      269 ms  CppClean                                   1 calls
	1>      798 ms  SetModuleDependencies                     10 calls
	1>     1232 ms  CL                                         2 calls
	1>     1439 ms  MultiToolTask                              1 calls
	04.295 seconds

Submodules:

	1>      141 ms  MSBuild                                   16 calls
	1>      775 ms  SetModuleDependencies                     10 calls
	1>     1015 ms  CL                                         2 calls
	1>     1132 ms  MultiToolTask                              1 calls
	03.427 seconds

The CL entry is for cpp files and it's 4.39x as fast as header-based. Great!

But it's the ixx dependency scanning and compilation (MultiToolTask) that brings things down. Things that aren't there with header-based.

MultiToolTask is parallelised though. Reducing thread count slows it down. And you can open up the msbuild binlog in the msbuild log viewer to see the parallelisation of ixx compilation. See which modules are on the end of the DAG slowing things down.

So, I don't know how MultiToolTask could be sped up, but, msbuild seems to be waiting for all ixx files before moving onto cpp files, so that's some parallelism left on the table.

Detailed timings of App:

Header-based, app pch:

	1>      196 ms  MSBuild                                   13 calls
	1>     1000 ms  Link                                       1 calls
	1>    23270 ms  CL                                        16 calls
	24.708 seconds

Extlib modules + CommonStuff submodules:

	1>      199 ms  SetModuleDependencies                     18 calls
	1>      606 ms  MSBuild                                   27 calls
	1>     1197 ms  Link                                       1 calls
	1>    21877 ms  CL                                        15 calls
	24.078 seconds

Full submodules:

	1>      459 ms  MSBuild                                   27 calls
	1>     1324 ms  Link                                       1 calls
	1>     4646 ms  SetModuleDependencies                     18 calls
	1>    12593 ms  MultiToolTask                              1 calls
	1>    49327 ms  CL                                        15 calls
	01:09.245 minutes

Slow. But looking at the log viewer, ixx compilation seems very well parallelised.

And 4.6s just to scan for dependencies. VS isn't launching a whole CL process for each file is it?

Also, why does CL take so long? All modules have been compiled by that point, so why would it be much slower?

Recompiling a single file from App:

Header-based, no pch:

	1>       46 ms  SetModuleDependencies                     10 calls
	1>      120 ms  MSBuild                                    5 calls
	1>     3757 ms  CL                                         1 calls
	04.095 seconds

Header-based, app pch:

	1>       56 ms  SetModuleDependencies                     10 calls
	1>      121 ms  MSBuild                                    5 calls
	1>     1793 ms  CL                                         2 calls
	02.059 seconds

Extlib + CommonStuff modules (as submodules):

	1>      121 ms  SetModuleDependencies                     18 calls
	1>      216 ms  MSBuild                                   17 calls
	1>     1793 ms  CL                                         1 calls
	02.162 seconds

Full submodules, except app:

	1>      518 ms  MSBuild                                   17 calls
	1>      631 ms  SetModuleDependencies                     18 calls
	1>     2211 ms  CL                                         1 calls
	03.095 seconds

Full submodules:

	1>      559 ms  MSBuild                                   17 calls
	1>      696 ms  SetModuleDependencies                     18 calls
	1>     1891 ms  MultiToolTask                              1 calls
	1>     3221 ms  CL                                         1 calls
	06.331 seconds

That MultiToolTask is quite slow, checking that all the modules in the project are up to date it seems. Does it have to be this slow?

"CL.exe will run on 0 out of 224 file(s) in 224 batches. Startup phase took 2040.9372ms."

Anyway.

Conclusion:

  • I now have the data to know how I should go about modularising a codebase for build perf.
  • Surprisingly, there is a middle-ground between 0% modules and 100% modules where you get optimal build performance. It seems extlibs and your common lib should be modularised and nothing else. Or maybe my internal lib headers are too small to benefit.
  • Because of that, I might be able to have a header-based fallback for intellisense without it spreading to the rest of the code.
  • Multiple modules > Partitions. Partitions have worse performance. I assume that's because they need to have an extra module at the end of the DAG.

    • Their only advantage is shared module attachment across multiple ixx files, if you don't use extern "C++". As I said before, I wish you could have "public" partitions or multiple modules with the same name attachment.
  • MSVC partition cpp files are slightly faster vs module cpp files. But why. Cpp files wait for all ixx files to compile anyway. Noise in the data?
  • MSBuild parallelises as it should, it seems, except that cpp files wait for all ixx files. Could improve performance by merging the tasks?
  • cpp compilation can be much faster, but overall build perf brought down by ixx files and scanning.
  • Moving implementation to ixx files doesn't always help. Need more data.

    • And it would be ideal if build systems avoided the build cascade when only changing implementation details.
  • The more modules you add to the solution, the more bloated the build system feels. Lots of scanning, lots of ixx checking. Can performance be improved?
  • PCH can be beaten in some cases.

Problems:

  • Intellisense. Red squiggles everywhere. Not only import std issues, but Intellisense is highly sensitive to errors in imported modules. It cannot limp along like it can with headers.

    • A simple example would be missing a semicolon after a struct def in a header and in a module. Intellisense can still use the struct from the header, but not the module.
    • Or in working code, something from import std that Intellisense can't handle.
    • This means that parsing issues with Intellisense may be viral when using modules. Intellisense must either be perfect or tolerant.
  • From a previous modularisation attempt, I removed the combination of explicit template instantiations of a class with constrained friend functions, due to ICE, which has now become a bogus compiler error. Bug not fixed.
  • Lots of linker warnings from dllexport-ed manual RTTI data. Bug not fixed.

At least the compiler functions well enough to produce a working program with no further changes. That's pretty good.


r/cpp • • Jul 29 '26

const_cast: A Necessary Evil

Thumbnail elbeno.com
70 Upvotes