r/cpp • u/llort_lemmort • 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
View all comments
Show parent comment
8
u/jpakkane Meson dev Jul 02 '26 edited Jul 02 '26
The underlying issue here is the definition of "fast". It is subjective. Your test includes all of the stdlib headers and it takes 0.67 seconds. In your opinion that is "fast" and that is totally fine. 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.
As for the LLM generated code sample, not knowing what it actually does (it is LLM slop after all) makes it hard to judge. But assuming it does an "ok" job, the outcome is still (again, to me, personally and subjectively) maddeningly slow. Having things take seconds instead of fractions of a second makes the development experience miserable. It should also be noted that some parts of the stdlib are much slower than others. Examples of commonly used but slow parts include
variantandprint. A more representative example would include many different instantiations of those but autogenerating a representative data set for that is pretty much impossible.It takes 10 seconds also for me on this computer if I'm using all cores. However the tests in question were done using
-j 1. With that the compilation takes 50 seconds.More importantly if you use Ninjatracing to find where the time actually goes, things get much more interesting. On this machine with a non-optimized build there are several source files that take up to 8 seconds to compile each. These include
document.cppandcapi.cpp. If they were doing some super optimized particle simulation computations or the like this would be totally acceptable. Specialised code can take as long as it needs to. But this is not special, those files are doing simple and boring things with strings, integers, arrays and unordered maps. The files should take at most one second to compile and with Pystd they do (from memory, did not validate this).No, I specifically said 80% and stand by that. 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 a project has other, heavy duty C++ dependencies, then obviously the speedup will be less. But we don't have actual real world measurements, so we don't know for sure.
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 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.