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 articleThe {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.
Related
Some Tricks from the Scrapscript Compiler
The Scrapscript compiler implements optimization tricks like immediate objects, small strings, and variants for better performance. It introduces immediate variants and const heap to enhance efficiency without complexity, seeking suggestions for future improvements.
#F – A Minimalistic Scheme System
#F is a minimalistic Scheme system that compiles to portable C code for integration with C projects. It is not standard-compliant and has performance limitations, with installation requiring C file compilation.
Another variable-length integer encoding
The article presents two encoding schemes for small integers in binary formats: metric varint and imperial varint, highlighting their efficiency, advantages, and the use of zig-zag encoding for signed integers.
Small Strings in Rust: smolstr vs. smartstring
The article explores Rust's small string libraries `smolstr` and `smartstring`, demonstrating JSON parsing, a custom memory allocator, and a reporting subcommand for analyzing memory usage and allocations.
Rust's Ugly Syntax (2023)
The blog post addresses complaints about Rust's syntax, attributing them to misunderstandings of its semantics. It suggests simplifying semantics for readability while maintaining performance and safety features.
Related
Some Tricks from the Scrapscript Compiler
The Scrapscript compiler implements optimization tricks like immediate objects, small strings, and variants for better performance. It introduces immediate variants and const heap to enhance efficiency without complexity, seeking suggestions for future improvements.
#F – A Minimalistic Scheme System
#F is a minimalistic Scheme system that compiles to portable C code for integration with C projects. It is not standard-compliant and has performance limitations, with installation requiring C file compilation.
Another variable-length integer encoding
The article presents two encoding schemes for small integers in binary formats: metric varint and imperial varint, highlighting their efficiency, advantages, and the use of zig-zag encoding for signed integers.
Small Strings in Rust: smolstr vs. smartstring
The article explores Rust's small string libraries `smolstr` and `smartstring`, demonstrating JSON parsing, a custom memory allocator, and a reporting subcommand for analyzing memory usage and allocations.
Rust's Ugly Syntax (2023)
The blog post addresses complaints about Rust's syntax, attributing them to misunderstandings of its semantics. It suggests simplifying semantics for readability while maintaining performance and safety features.