Hasty Briefsbeta

Bilingual

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

6 days ago
  • #Standard Library
  • #C++
  • #Compilation Speed
  • The author discusses Pystd, a from-scratch written standard library for C++ designed to improve compilation times, which is not an implementation of the ISO specification.
  • C++ compilation is significantly slower than C, with a 'hello world' program taking up to 2.3 seconds in C++ compared to 0.02 seconds in C, a slowdown of about 100x.
  • The slowdown is attributed to the standard library implementation, where including headers like <vector> expands to around 29,000 lines of preprocessed code, increasing compile times.
  • Pystd's design priorities are compilation time, simplicity of implementation, and performance, aiming to reduce build times with a requirement that any header compile within 0.15 seconds.
  • Pystd currently has 6,500 lines of headers and 5,600 lines of source code, offering functionality such as containers (vector, hash maps), algorithms, smart pointers, and utilities similar to Python modules.
  • Adopting Pystd led to an 80% reduction in compile times, up to 75% reduction in unstripped binary size, and a 25% improvement in runtime performance for the CapyPDF library.
  • The project includes a performance test script to enforce compile time limits, even on slower hardware like a Raspberry Pi, and supports Linux and macOS but not MSVC due to missing compiler features.
  • Lack of documentation is acknowledged; the author suggests using AI tools for generating docs but avoids including AI-generated content in the repo for ethical reasons.