August 30th, 2024

Honey, I shrunk {fmt}: bringing binary size to 14k and ditching the C++ runtime

The {fmt} library has reduced its binary size to 23kB by using type erasure, maintaining runtime type safety, and optimizing for memory-constrained environments, including retro computing applications.

Read original articleLink Icon
Honey, I shrunk {fmt}: bringing binary size to 14k and ditching the C++ runtime

The {fmt} formatting library has achieved a significant reduction in binary size, now reaching as low as 23kB, while eliminating the need for the C++ runtime. This reduction is primarily due to the library's innovative use of type erasure, which minimizes template bloat and confines template usage to a minimal top-level layer. The library's design allows for efficient formatting without sacrificing runtime type safety, catching format string errors at compile time and managing runtime errors through exceptions. Recent optimizations include disabling locale support and utilizing an extension API for formatting arbitrary types, which further reduces the binary size. The library's performance remains robust, particularly for positional arguments, and it has garnered interest for use in memory-constrained environments, including retro computing. The latest tests indicate that the binary size has not significantly regressed despite ongoing developments, and further optimizations are being explored to enhance efficiency while maintaining a small footprint.

- The {fmt} library's binary size has been reduced to as low as 23kB.

- Type erasure is used to minimize template bloat and improve build times.

- The library maintains runtime type safety and manages errors effectively.

- Recent optimizations include disabling locale support and using an extension API.

- The library is suitable for memory-constrained devices and retro computing applications.

Link Icon 2 comments
By @npalli - 8 months
fmt is one the best libraries to come out of modern C++. Safety, performance, ease of use, versatility. Something every library should aspire to.
By @klooney - 8 months
Incredible!