short

Less standard library, faster program

· english· audience: working-cpp· AI-generated, reviewed by Filip Sajdak

A C hello world compiles in about 0.02 seconds. The C++ equivalent that pulls in #include <print> takes roughly 1 second without optimizations and up to 2.3 seconds with them. That is a 100x tax before you write a line of your own code. Jussi Pakkanen, the creator of the Meson build system, blames the standard library headers, and his from-scratch replacement, Pystd, lets him back the claim up: rewriting his own code against it made the build faster, the binary smaller, and the program faster at once.

The cost lives in the headers. Preprocess a single include and watch it bloom: <vector> expands to about 29,000 lines, <memory> to 55,000, <print> to 65,000, <filesystem> to 80,000. As he puts it, almost 30k lines just to get a growable array seems a bit much.

What Pystd covers

Pystd is deliberately not ISO C++. It drops backwards compatibility and reimplements the commonly used subset: vector, string, u8string, spans, a hash map and a B-tree ordered map, unique_ptr, optional, expected, variant, plus Python-flavored conveniences like argparse, a pathlib with a ** operator, PCRE-backed regex, and tempfile. The whole library is about 12,000 lines, roughly a third of what one preprocessed std::vector costs. It uses a pystd<year> versioning namespace so old code stays frozen while new releases evolve freely.

The CapyPDF conversion

Numbers from a toy are easy to dismiss, so Pakkanen converted a real shipping library, his CapyPDF, to use Pystd instead of the standard library. The result:

  • compile time: about 80% lower
  • unstripped binary: about 75% smaller
  • stripped binary: about 30% smaller
  • runtime: about 25% faster

Nothing was traded away at runtime to get the faster build. Less abstraction for the compiler to see through means less code to instantiate, a smaller binary, and less indirection at runtime. To keep it that way as the library grows, he enforces a hard rule in CI: including any single public header must compile within 0.15 seconds, and it has to hold even on a Raspberry Pi.

Where Pystd stops short

Pystd will not drop into an existing std::-based codebase, and Pakkanen does not pretend it will. Nothing in the ecosystem speaks its types, so every boundary with a library that wants std::string or std::vector needs a conversion. It builds only on GCC and Clang, Linux and macOS. MSVC is out, because Pystd leans on pack indexing that MSVC has not shipped. And the post is quiet on the genuinely hard parts of a standard library: exceptions, RTTI, allocators, iterator invalidation contracts, thread-safety guarantees. “One third the size” is partly a comparison against work not yet done.

The committee’s own answer to the same pain is import std; and modules, which attack header expansion without abandoning conformance. That is the fairer comparison for Pystd.

The caveats do not undo the result. The slowness people blame on “C++” is often the library implementation, not the language, and a hard per-header compile budget is a discipline any team can adopt on its own code today.


Sources: Jussi Pakkanen, “Pystd, a standard library similar-ish to the real one” (June 2026). Code at github.com/jpakkane/pystd.