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
49
u/chibuku_chauya Jul 02 '26
Calling it Pystd makes me think thereβs Python involved here.
33
u/matthieum Jul 01 '26
On the one hand, I appreciate the idea...
... on the other hand, it's high times for modules :'(
12
u/fdwr fdwr@github π Jul 02 '26 edited Jul 02 '26
Nice. I'm mystified by the variance of
stdbloat sometimes from using just one function. I have a 12KB program that's pure Win32 (no CRT), and using a singlestd::vectoradds 2KBs (tolerable), and using a singlestd::println("Foo")adds 3KBs (tolerable), but just onestd::println("Foo: {}", x)suddenly bumps 12KB's -> 212KB's o_o, and that's with all the size-reducing options I can think of {MSVC x86 release build, maximum optimization (favor size /O1), favor small code (/Os), enable function level linking (/Gy), enable COMDAT folding (/OPT:ICF), link time code generation (/LTCT), references eliminate unused (/OPT:NOREF)}. The weird thing is that I can call thatstd::printlninside a completely unused function, and it still bloats the exe. Granted, maybe that's anstdimplementation issue more than withstditself, or an issue with dead code elimination π€·ββοΈ.5
u/slithering3897 Jul 01 '26
Yeah, and X% of the time, I only need
pathin a header. So I made a struct that inherits frompathjust so I can forward declare it. C++!That would be easily solved by modules.
Then you have the
std::printproblem. Modules will help, but big savings can only come from aggressive template reuse./dxifcInlineFunctions-may be useful in debug builds.4
u/Commercial-Berry-640 Jul 01 '26
I like the project.
2
u/diegoiast Jul 05 '26
This is becoming great. The D community had this same problem. The ability to use another standard library is a great idea.
One suggestion if you don't mind: use a subdir and not prefixes for your includes. I will link to Linus complain which he did for similar problem: https://lore.kernel.org/lkml/CAHk-=wghMm2c+AYEcwYY7drSVXB27DYqc-ZXpFiq=XFs-w59wA@mail.gmail.com/https://lore.kernel.org/lkml/CAHk-=wghMm2c+AYEcwYY7drSVXB27DYqc-ZXpFiq=XFs-w59wA@mail.gmail.com/
3
u/karurochari Jul 01 '26
To be honest, I mostly solved the "time" issue with precompiled headers.
Mostly, because getting them to play with OpenMP offloading is painful in Clang, and intrinsically broken for GCC as far as I can tell.
But I reckon it would be good time for a v2 of the standard library, one which can be built from zero, ignoring the huge technical debt mostly linked to backwards compatibility and questionable design decisions in the 90s.
4
u/13steinj Jul 02 '26 edited Jul 02 '26
This is a very bad falsehood that continues to perpetuate. You can include the entire standard library and on modern hardware compiling it is on the order of a minute or less, often in seconds.
Your project is on the order of 15k lines of code (this is not including tests, but that does not raise it that much).
On my less-than-perfectly-modern-hardware, a full build of your codebase takes takes less than 10 seconds (please tell me if I am missing something / that should be impossible, ).
So if 10 seconds is "20%", the before-time was (let's round) 50 seconds. If you look at the other post on the front page, you'll see that people have to suffer through far worse than a minute for their builds. I suspect you said "80%" but you should have said "40 seconds."
Of course, compiling the universe as I did above, but not using it is not a fair benchmark. So, I had an LLM use every feature of the standard library / instantiate every symbol. it's not _perfect, but it did a pretty good job. The
-Bis a result of my system picking the wrong static linker which is relevant for libc nuances. The result:Even if you assume the LLM was so bad that it only got 20% of the stdlib, 20-40 seconds for everything is not "slow."
E: the first command I misquoted with the copy paste of my first modification.
E: this is not to say your "pystd" is not valuable in some way, and there's other "stdlibs" of similar nature. One tries to mimic the Rust stdlib instead. I'm just tired of the complete disparity in compile time claims. People read articles like this and read the high percents and then blame it the same way in their own projects, or apply the same thinking to blaming Boost (it is worse with Boost, but most people don't use the worst offenders that become an actually significant portion of their compile times). It perpetuates "modules will save us," when that's just not true, and is as bad as "Bazel is more performant" or "templates are inherently bad for compile times."