Wednesday, January 15

Tag: buffer

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

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

Technology
The {fmt} formatting library is known for its small binary footprint, often producing code that is several times smaller per function call compared to alternatives like IOStreams, Boost Format, or, somewhat ironically, tinyformat. This is mainly achieved through careful application of type erasure on various levels, which effectively minimizes template bloat.Formatting arguments are passed via type-erased format_args:auto vformat(string_view fmt, format_args args) -> std::string; template auto format(format_string fmt, T&&... args) -> std::string { return vformat(fmt, fmt::make_format_args(args...)); } As you can see, format delegates all its work to vformat, which is not a template.Output iterators and other output types are also type-erased through a specially designed buffer API.Thi...