r/cpp • • Jul 01 '26

Pystd standard library, similar-ish functionality with a fraction of the compile time

https://nibblestew.blogspot.com/2026/06/pystd-standard-library-similar-ish.html
50 Upvotes

17 comments sorted by

View all comments

Show parent comment

0

u/13steinj Jul 02 '26 edited Jul 02 '26

However in my personal opinion that is at least 5x too slow given the functionality it provides. There are various legacy reasons why that is the case, hats off to the stdlib developers for making it as fast as it is.

Less than a minute is fast. You can debate with people about how "that's subjective" until the cows come home, but people have commonly complained about 10+ minute build times on this subreddit. Some have expressed 2 hours. Some have even expressed multi-day build times.

It is very difficult to extrapolate from a sample size of one, but the basic assumption here is that the stdlib slowdown is "approximately linear". Given a project with a similar setup as CapyPDF (i.e. no other C++ dependencies than the stdlib, doing a whole project conversion) then that is the build time improvement you should expect.

If you just had more code, your "approximately linear" assumption breaks down very quickly. If you have approximately the same amount of code in a different manner (I deal with single TUs that are 10 minutes and low-dependency, as I've mentioned in the other thread), it breaks down even quicker.

However the tests in question were done using -j 1. With that the compilation takes 50 seconds....On this machine with a non-optimized build there are several source files that take up to 8 seconds to compile each.

When the above (multi hour, multi-day build times, multi-minute single-TU times) is included in your distribution, you stop caring very quickly about anyone who claims they've sped up their build by double-digit percentages... from less than a minute to lesser than a minute.


E: also, while -j 1 is a nice goal, the long compile times I am mentioning elsewhere in this comment are -j 24+. To get a sense of just how bad the distribution is. If every TU includes the stdlib, sure, you'll be linear, to how many TUs you have.


Bringing all that together in a very tl/dr way, it is my personal opinion that when using a single core for general, "boring" code the compilation process should be fast enough for throughput to be closer to three files per second than three seconds per file.

I mean, that depends on what you call "boring." I had what I would call a bunch of boring log/assert-statement-like code. I reduced build-times by double-digit percentages on multi-minute TUs, and there, I am happy to use percentages, because the way I did it is guaranteed to be linear. I swapped out the tuple implementation for that within Boost.Hana in a key area, and the std::function implementation for one that didn't use std::tuple under the hood to pass arguments around.

Over 30% saved, std::function and std::tuple were still in-use in the TUs, their headers still included-- and now more headers and code included too, but more efficient template instantiations.

Using lines of code as your negative-correlation analog for compile time is about as useful as using it as your positive-correlation metric for developer productivity.

When doing so about lines of code, your speedup is fundamentally a constant (though, you can consider it a multiplier / percentage to a point for unique template instantiations). Including <vector> is a constant amount of time, related to the lines of code therein. Instantiating it is linear, to the amount of std::vector code (not everything else that supports it that isn't templated) x the number of unique instantiations.

I know that said speeds are probably unachievable with the default standard library as it stands, but still that should be the target, especially for custom standard libraries.

Realistically it's unachievable no matter what standard library you use, unless you cut corners and make these things work for far fewer cases than they currently do. But what people end up realizing as they do this, is that when everyone has their own snowflake vector implementation to compile, and you have to write translation code to match, you end up increasing compile times, not decreasing them.

4

u/jpakkane Meson dev Jul 02 '26

Less than a minute is fast. You can debate with people about how "that's subjective" until the cows come home, but people have commonly complained about 10+ minute build times on this subreddit. Some have expressed 2 hours. Some have even expressed multi-day build times.

You are comparing apples to oranges. The former is "how long does it take to compile a single, scoped source file" whereas the latter is "how long does it take to compile a huge source file in an existing project that does a whole bunch of stuff". They are fundamentally different things and trying to squeeze them into a same shaped box does both a disservice.

We just have to agree to disagree on what is fast or not. And that is totally fine.