Skip to content

Documentation: Improve guidance on compile-time options for binary size reduction #4549

@teruyamato0731

Description

@teruyamato0731

Hello, and first of all, thank you for the excellent {fmt} library. It's a powerful and essential tool for modern C++ development.

I am opening this issue to suggest an improvement to the documentation, specifically regarding the compile-time options available to reduce binary size.

Motivation

I am currently using {fmt} in an embedded environment as a replacement for std::format, with the primary goal of minimizing binary size. The library's documentation rightly highlights its small binary footprint, which is a major reason for its adoption in resource-constrained environments like mine.

While I was ultimately successful in significantly reducing the binary size by passing specific compile-time flags, I found that these options are not documented in a centralized or easily discoverable location.

The Challenge

My experience finding the right options involved:

  • Sifting through changelogs where some flags were mentioned.
  • Difficulty searching, as the term "macro" is generic and results are often mixed with deprecated flags from older versions or notes about them being disabled.
  • A process of trial and error to find the combination that worked.

This makes it challenging for users, especially those who are specifically choosing {fmt} for its size benefits, to achieve those benefits without significant self-directed research.

Concrete Results

To demonstrate the impact of these flags, here are the binary size measurements from my environment. The difference is substantial.

Method Binary Size
std::format 317 KiB
{fmt} (default configuration) 210 KiB
{fmt} with size-optimization options 29 KiB
<cstdio> printf only (for baseline) 18 KiB

The options I used to achieve the 29 KiB size were:

  • FMT_BUILTIN_TYPES=0
  • FMT_OPTIMIZE_SIZE=1
  • FMT_USE_LOCALE=0

Proposal

I believe the documentation would be greatly improved by adding a dedicated section that covers compile-time configuration. This section could include:

  1. A comprehensive list of all available compile-time options (e.g., FMT_HEADER_ONLY, FMT_USE_EXCEPTIONS, etc.).
  2. A clear explanation of what each option enables, disables, or changes.
  3. A specific guide or "recipe" for users who want to optimize for minimal binary size, explaining which flags are most effective.
  4. A complete, buildable example, including a sample CMakeLists.txt, that demonstrates how to apply these settings to achieve a minimal footprint.

For reference, these are some of the options I came across during my research:

  • FMT_HEADER_ONLY
  • FMT_USE_EXCEPTIONS
  • FMT_OS
  • FMT_BUILTIN_TYPES
  • FMT_OPTIMIZE_SIZE
  • FMT_USE_LOCALE

Making this information more accessible would be incredibly valuable for the embedded community and anyone else concerned with code size. It would solidify {fmt}'s position as the go-to solution for high-performance, low-overhead formatting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions